/**
 * Created by jackshall on 2020/7/10.
 *
 *
 */
// var datax = {
//     wayBillNo: '103469371015',
//     complaintBigType: '1',
//     complaintBigTypeName: '理赔类',
//     complaintLittleType: '6682832665046949888',
//     handleProvinceCode: 'shanghai',
//     handleDepartmentCode: '431B',
//     handleDepartmentName: '长师直营部',
//     responsibilityLink: 1,
//     callBackTimeWithin: 1,
//     businessType: 2,
//     abType: 1,
//     complaintReason: '111111',
//     telNumber: 15236987854,
//     customerName: '先生',
//     productType: 'CP02',
//     customerType: 1,
//     handleDeptType: 2,
//     fromCompCode: 'jilinsheng',
//     toCompCode: 'sichuan',
//     token: '1cd655e9beaa454487271f78227d71c9',
//     workNoMark: '090393',
// }
//     运单信息
    var billData={};
    var billData2={};
    // 工单信息
    var gdEd=[],gdIng=[]
    var apiUrl = G_CTX_PATH;
    var customerTypeData=[];
$(window).resize(function(){
    $("#newlogisticsInformationDataGrid").datagrid("resize");
    $("#newproblemInformationDataGrid").datagrid("resize")
});
// var twaybillNum="103469408765"
    console.log("---")
// var datax={
//     wayBillNo: '103469408765',
//     complaintBigType: '1',
//     complaintBigTypeName: '理赔类',
//     complaintLittleType: '6682832665046949888',
//     handleProvinceCode:'',
//     handleDepartmentCode: '021MB',
//     handleDepartmentName: '泗泾北营业部',
//     responsibilityLink: '1',//责任环节
//     callBackTimeWithin:'2',
//     businessType: '1',
//     abType: '2',//不明
//     complaintReason: 'ccostest',/** 投诉原因 */
//     telNumber: '17612174369',
//     customerName: '先生',
//     productType: 'CP02',/* 产品类型 */
//     customerType: '1',/** 客户类型 */
//     handleDeptType:'',
//     fromCompCode: 'shanghai',
//     toCompCode: 'shanghai',
// }
function customerTypes(keys) {
    var data = $("#custType").combobox("getData");
    console.table(data)
    if(keys){
        for (var i=0;i<data.length;i++){
            if(data[i].key == keys){
                return data[i].value
            }
        }
    }
    console.log(data)
}
// 客户来源
function dealcustomerComplaintSource(a) {
    if (a= "1") {
        return  "热线电话";
    }
    if (a= "2") {
        return  "在线客服";
    }
    if (a= "3") {
        return  "微信客服";
    }
    if (a= "4") {
        return  "监督热线";
    }
    if (a= "5") {
        return  "官方网站";
    }
    if (a= "6") {
        return  "手机APP";
    }
}
 function dealabType(a) {
    if (a== "1") {
        return  "A";
    }
    if (a== "2") {
        return "B";
    }
}
   function dealbillStatus(a) {
    if (a == "1") {
        return"待抢单";
    }
    if (a == "2") {
        return"待处理";
    }
    if (a == "3") {
        return"处理中";
    }
    if (a == "4") {
        return"已结办";
    }
    if (a == "5") {
        return"已结单";
    }
    if (a == "7") {
        return"结办审核中";
    }
}
function dealbusinessType(a) {
    if (a == "1") {
        return "企业内";
    }
    if (a == "2") {
        return "企业外";
    }
}
function  dealComplaintant(a) {
    if (a== "1") {
        return"内部投诉";
    }
    if (a== "2") {
        return"外部投诉";
    }
}
function dutyText(keys) {
    var data =$("#zrhj").combobox("getData");
    if(keys){
        for (var i=0;i<data.length;i++){
            if(data[i].key == keys){
                return data[i].value
            }
        }
    }
}
function sxName(keys) {
    var data =$("#hdsx").combobox("getData");
    if(keys){
        for (var i=0;i<data.length;i++){
            if(data[i].key == keys){
                return data[i].value
            }
        }
    }
}
// 重复投诉
function cfts() {
    console.log();
    if(!$(".reComplainReson").textbox('isValid')){
        return;
    }
    var reComplainReson = $(".reComplainReson").textbox("getValue");
    var id = $(".workBillNo").text();
    if(!reComplainReson){
        showInfoMsg("请输入重复投诉原因！")
    }else{
        $.ajax({
            url:apiUrl+"/ccos/waybill/repeatWorkBill.do",
            data:{
                workBillNo:id,
                handleResult:reComplainReson
            },success:function (e) {
                console.log(e);
                if(!e){
                    return;
                }
                if(e.success){
                    showInfoMsg("操作成功！");
                    $("#reComplain").dialog("close");
                    // $("#reComplainReson").setValue("")
                    // $('#reComplain').dialog('open')
                    $(".reComplainReson").textbox("setValue","");
                    return
                }else{
                    var e = JSON.parse(e);
                    if(e.success){
                        showInfoMsg("操作成功！");
                        $("#reComplain").dialog("close");
                        // $("#reComplainReson").setValue("")
                        // $('#reComplain').dialog('open')
                        $(".reComplainReson").textbox("setValue","");
                    }else {
                        showInfoMsg("操作失败！");
                    }
                }

            }
        })
    }
}
// 创建工单
function cjgd() {
    $('#submitButton').linkbutton('disable')
    // $('.tjbtn').linkbutton('disable');
    var isFW = $("#neworderType").combobox("getValue")=="2"?true:false;
    var isXD = $("#neworderType").combobox("getValue")=="36"?true:false;
    var wayBill = $("#waybillNum").textbox("getValue");
    if(isFW||isXD){
        if(isXD){
            var xdBle = xd();
            if(xdBle === false){
                $('#submitButton').linkbutton('enable');
                return
            }
            return
        }

    }else{
        if(!wayBill){
            showInfoMsg("请输入运单号");
            $('#submitButton').linkbutton('enable')
            return
        }
        if(!billData2.column9){
            showInfoMsg("请输入运单号并查询运单信息");
            $('#submitButton').linkbutton('enable');
            return
        }
    };
    var datax ={}
    var b=$("#gdForm").form("validate");
    var a =$("#customerInformationForm").form("validate")
    var adata = serializeFormObj("gdForm");
    var bdata = serializeFormObj("customerInformationForm");
    bdata.customerName= bdata.custName;
    bdata.customerType = bdata.custType
    datax.wayBillNo =wayBill ;
    if(a&b){
        adata.complaintBigTypeName = $("#neworderType").combobox("getText");
        datax.handleDepartmentCode = $("#xxdutyWebsite").combogrid("getValue");
        datax. handleDepartmentName =$("#xxdutyWebsite").combogrid("getText");
        datax.complaintBigTypeName = $("#neworderType").combobox("getValue");
        if(isFW||isXD){
            datax.handleProvinceCode = "";
            datax.businessType = "";
            datax.abType = "";
            datax.productType = "";
            datax.fromCompCode = "";
            datax.toCompCode = "";
        }else{
            datax.handleProvinceCode = billData2.toCompCode;
            datax.businessType = billData2.businessModel;
            datax.abType = billData2.column9;
            datax.productType = billData2.productType;
            datax.fromCompCode = billData2.compCode;
            datax.toCompCode = billData2.toCompCode;
        }
        datax.handleDeptType = $('#xxdutyWebsite').combogrid('grid').datagrid('getSelected').deptType;
        Object.assign(datax,adata,bdata);
        $.ajax({
            url:apiUrl+"/ccos/workOrder/addWorkOrder.do",
            data:datax,
            success:function (data) {
                $('#submitButton').linkbutton('enable')
                console.log(data);
                if(data.success){
                    var e = JSON.parse(data.message)
                    showInfoMsg(e.msg);
                    $("#gdForm").form("reset");
                }
            }
        })
    }else{
        showInfoMsg("请确定所有必填项都已填写！");
        $('#submitButton').linkbutton('enable')
    }

}
function dateFormate(date) {
    if(!date){
        return "";
    }
    var date = new Date(date);
    return [date.getFullYear(),date.getMonth()+1,date.getDate()].join("-")+" "+[date.getHours()<10?"0"+date.getHours():date.getHours(),date.getMinutes()<10?"0"+date.getMinutes():date.getMinutes(),date.getSeconds()<10?"0"+date.getSeconds():date.getSeconds()].join(":");
};
//工单详情
function showGdDet(type,index) {
    var tab = $("#leftCsSmOrdeTab").tabs('getSelected');
    var indexTab = $("#leftCsSmOrdeTab").tabs('getTabIndex',tab);
    if(indexTab == 1){
        $(".ts").show();
    }else{
        $(".ts").hide()
    }
    console.log($("#newprocessingCustSerOrderDataGrid").datagrid('getData').rows[index]);
    if(type == 0){
        var rowData = $("#newprocessingCustSerOrderDataGrid").datagrid('getData').rows[index];
    }else {
        var rowData = $("#ywjgdTable").datagrid('getData').rows[index];
    }
    $(".chulijilu").datagrid({
        data:[]
    });
    $(".liuzhuanjilu").datagrid({
        data:[]
    })
    rowData.customerComplaintSourceName = dealcustomerComplaintSource(rowData.customerComplaintSource);
    rowData.abTypeName = dealabType(rowData.abType);
    rowData.dealbillStatus = dealbillStatus(rowData.billStatus)
    rowData.businessTypeName = dealbusinessType(rowData.businessType)
    rowData.complaintantName = dealComplaintant(rowData.complaintant)
    rowData.customerTypeName=customerTypes(rowData.customerType)
    rowData.responsibilityLinkName = dutyText(rowData.responsibilityLink)
    // rowData.callBackTimeWithinName = sxName(rowData.callBackTimeWithin)
    rowData.callBackTime = formatTime(rowData.callBackTime)
    rowData.createrTime = formatTime(rowData.createrTime)
    var dom = $(".gdxqTable td");
    for(var i =0;i<dom.length;i++){
        var key=dom.eq(i).attr("class");
        dom.eq(i).text(rowData[key]?rowData[key]:rowData[key] == "0"?"0":"")
    };
    // console.log($("#tttabs").tabs("getSelected"));
    // var tab =$("#tttabs").tabs("getSelected")
    // var  index = $('#tttabs').tabs('getTabIndex',tab)
    // $("#tttabs").tabs("select",0)

    // gdjl(2);
    $("#diaGd").window('open');
    var tabHis = $("#tttabs").tabs('getSelected');
    var indexTabHis = $("#tttabs").tabs('getTabIndex',tabHis);
    if(indexTabHis == 1){
        gdjl(2);
    }else{
        gdjl(1);
    }
}
// 问题件详情
function showWTdeta(value) {
    var columns = [[
        {field:'receiveDeptName',title: '通知方',align: 'center',width:150},
        {field:'dealDeptName',title: '回复方',align: 'center',width:150},
        {field:'dealContent',title: '回复内容',align: 'center',width:150},
        {field:'createrTime',title: '回复时间',align: 'center',formatter:function (value) {
            return formatTime(value)
        },width:150},
    ]];
    $("#talkRep").datagrid("loadData",{total:0,rows:[]})
    $.ajax({
        url:apiUrl+"/ccos/waybill/problemreportinfo.do",
        data:{
            problemNum:value
        },success:function (e) {
            console.log(e);
            if(e.success){
                var rowData = e.data.problemreportinfo;
                var dom = $(".wtjxqTable td");
                for(var i =0;i<dom.length;i++){
                    var key=dom.eq(i).attr("class");
                    dom.eq(i).text(rowData[key]?rowData[key]:"")
                }
                if(rowData.replyMessage){
                    $("#talkRep").datagrid({
                        columns:columns,
                        data:rowData.replyMessage
                    })
                }
                $("#diaWTJ").window('open');
            }
        }
    })
}
// 下单按钮
function xd(){
    var ddata = serializeFormObj("con-form");
    var cdata = serializeFormObj("msgForm");
    if($("#msgForm").form("validate")){
        if($("#con-form").form("validate")){
            if(ddata.isOffer){
                ddata.isOffer = true;
            }else{
                ddata.isOffer=false;
                ddata.offerMoney=""
            }
        }else{
            return false;
        }
        if(ddata.isCollection){
            ddata.isCollection = true
        }else{
            ddata.isCollection=false;
            ddata.collection=""
        }
        cdata.sendAddressCode = cdata.sendRegion;
        var receiveprovinceName = $("#receiveProvince").combobox("getText");
        var receivecityName =$("#receiveCity").combobox("getText")
        var receiveregionName =$("#receiveArea").combobox("getText")
        var receivedeliverStreetName =$("#receiveTown").combobox("getText")
        var receivestreet = $("#receiveAddress1").textbox("getValue")
        // var receiveProvince = $("#receiveProvince").combobox("getValue");
        // var receiveCity = $("#receiveCity").combobox("getValue");var provinceName = $("#sendProvince").combobox("getText");
        var sendProvince = $("#sendProvince").combobox("getValue");
        var sendProvinceName = $("#sendProvince").combobox("getText");
        var sendcityName =$("#sendCity").combobox("getText")
        var sendCity =$("#sendCity").combobox("getValue")
        var sendregionName =$("#sendArea").combobox("getText")
        var senddeliverStreetName =$("#sendTown").combobox("getText")
        var street = $("#sendAddress1").textbox("getValue")
        cdata.senderAddress=sendProvinceName +
            "-" +
            sendcityName +
            "-" +
            sendregionName +
            "" +
            senddeliverStreetName +
            cdata.Street;
        cdata.sourceCity = sendcityName;
        cdata.consigneeAddressCode = cdata.countys;
        cdata.province = receiveprovinceName;
        cdata.city = receivecityName;
        cdata.county = receiveregionName;
        cdata.street = street;
        cdata.consigneeAddress = receiveprovinceName +
            "-" +
            receivecityName +
            "-" +
            receiveregionName +
            "" +
            receivedeliverStreetName +
            cdata.towns;
        var data={};
        var consignName = $("#goodsName").textbox("getValue");
        data.consignName = consignName;
        Object.assign(data,ddata,cdata);
        console.log(data);
        debugger;
        $.ajax({
            url:apiUrl+"/ccos/order/save.do",
            data:{
                orderVos:JSON.stringify(data),
                isOffer: data.isOffer,
                offerMoney: data.offerMoney?data.offerMoney:"",
                isCollection: data.isCollection,
                collectionMoney: data.collectionMoney?data.collectionMoney:""
            },
            success:function (e) {
                console.log(e);
                if(e.success){
                    showInfoMsg("下单成功！",'','','提示');
                }else{
                    showInfoMsg("下单失败！",'','','提示')
                }
            }
        })
    }else{
        return false
    }

}

// 路由时效查询
function cxsx(a) {
    var data = serializeFormObj("cxform");
    console.log(data);
    if(!data.proType){
        data.proType="88"
    }
    if(a){
        data.startPoint = billData.wayBillInfoVo.startPointCode;
        data.endPoint = billData.wayBillInfoVo.endPointCode;
    }
    var columns = [[
        {field:'lineCode',title: '路线编码',align: 'center'},
        {field:'lineName',title: '线路名称',align: 'center'},
        {field:'outsetDep',title: '出发部门',align: 'center'},
        {field:'planGoTime',title: '计划发车时间',align: 'center'},
        {field:'arrivalDep',title: '到达部门',align: 'center'},
        {field:'planArrivalTime',title: '计划到车时间',align: 'center'},
        {field:'operateTime',title: '操作时间（分钟）',align: 'center'}
    ]]
    var dataGridParams = {
        // url:G_CTX_PATH+"/ccos/routTrack/routDetilInfo.do",
        // Method:'POST',
        queryParams:data,
        singleSelect : 'true',
        fitColumns : 'false',
        rownumbers: 'false'
    }
    $('#lysxTable').datagrid("loadData",{ total: 0, rows: [] });
    // newloadGrid('logisticsInformationDataGrid', columns, dataGridParams);
    $.ajax({
        url:apiUrl+"/ccos/routTrack/routDetilInfo.do",
        data:data,
        success:function (e) {
            if(e.success){
                if(!e.message) return;
                var datas =JSON.parse(e.message);
                console.log(datas);
                if(datas.routTimeList){
                    $('#lysxTable').datagrid({
                        data: datas.routTimeList,
                        columns:columns,
                        fitColumns : 'true'
                    });
                }
                $(".rtime").text(datas.routeTime);
                $(".ttext").text(datas.standardTime);
            }
        }
    })
}
function intGrid(data) {
    
}
function sxDiaShow() {
    $('#wxx').window('open');
    intcombogrid("qswd");
    intcombogrid('zdwd');
    combobAjax('cplx',"/ccos/routTrack/getrouttrakType.do",{},null,{key:"typeName",value:'typeCode'})
    $("#qswd").combogrid("setValue",billData.wayBillInfoVo.startPoint);
    // $("#qswd").combogrid("setValue",billData.wayBillInfoVo.startPointCode);

    $("#zdwd").combogrid("setValue",billData.wayBillInfoVo.endPoint);
    // $("#zdwd").combogrid("setValue",billData.wayBillInfoVo.endPointCode);

    $("#cplx").combobox("setValue",'88');
    $("#ctime").datetimebox("setValue",billData.wayBillInfoVo.creaTime);
    cxsx(true);
}


function changeFun(n,o) {
    console.log(n);
    console.log(o);
    $.ajax({
        url:G_CTX_PATH +'/ccos/org/queryDetial.do',
        data:{
            deptCode:n
        },
        success:function (data) {
            if(data.success){
                var data=data.data
                var text = "网点名称："+data.deptName+" " +
                    "网点编码："+data.deptCode+" " +
                    "网点地址："+data.detailAddress+" " +
                    "网点电话："+data.servicePhone
                $("#sendContent").textbox("setValue",text)
            }
        }
    })
}
function intcombogrid(id,fun) {
    $('#'+id).combogrid({
        delay: 500,
        url:G_CTX_PATH +'/ccos/org/getwebpointsforworkorder.do',
        idField: 'deptCode',
        textField: 'deptName',
        pagination:"true",
        panelWidth:400,
        fitColumns:false,
        queryParams:{
//                                                                        "orgType":"20",
            currentPage:1,
            "point":""
        },
        pageList:[10],
        columns: [[
            {field:'deptCode',title:'编号',width:200},
            {field:'deptName',title:'名称',width:200}
        ]],
        onChange:fun,
        keyHandler: {
            up: function() {},
            down: function() {},
            enter: function() {},
            query: function(q) {
                console.log("s")
                $('#'+id).combogrid("grid").datagrid("reload", { 'point': q,"orgType":"20"});
                $('#'+id).combogrid("setValue", q);
            }
        }
    });
}
function combobAjax(id,url,data,changeFun,keyValue) {
    console.log(data)
    $.ajax({
        url: G_CTX_PATH +url,
        data:data,
        success:function(data){
            console.log(data);
            var arr =data.data
            if(arr){
                $('#'+id).combobox({
                    valueField:keyValue?keyValue.value:'key',
                    textField:keyValue?keyValue.key:'value',
                    onChange:changeFun?changeFun:function () {

                    },
                });
                $('#'+id).combobox('loadData',arr)
            }
//                $("#year").combobox("loadData", yearArr);

        }
    });
}
function gdjl(type) {
    var id = $(".workBillNo").text();
    var datai =[];
    $(".chulijilu").datagrid('loadData', { total: 0, rows: [] });
    $(".liuzhuanjilu").datagrid('loadData', { total: 0, rows: [] });
    $.ajax({
        url:apiUrl+"/ccos/workOrder/getDealRecords.do",
        // method:"GET",
        data:{
            workBillNo: id,
            type: type
        },success:function (e) {
            console.log(e);
            if(e.success){
                if(e.data.data){
                    datai = e.data.data;
                }else{
                    datai =[]
                }
                if(type == 1){
                    $(".chulijilu").datagrid({
                        columns:[[
                            {field: 'createrName', title: '处理人', align: 'center'},
                            {field: 'createrDepartmentName', title: '所属机构', align: 'center'},
                            {field: 'createrProvinceName', title: '所属省区', align: 'center'},
                            {field: 'modifierTime', title: '处理时间', align: 'center',formatter: function (value) {
                        return formatData(value)
                    }},
                            {field: 'dealTypeName', title: '处理类型', align: 'center'},
                            {field: 'handlerInfo', title: '处理信息', align: 'center'},
                            {field: 'remindTime', title: '跟进提醒时间', align: 'center',formatter: function (value) {
                                return formatData(value)
                            }},
                            // {field: 'handlerAttachment', title: '附件', align: 'center',formatter:function (v,r,i) {
                            //     return "<a href='#' onclick='download("+index+")'></a>"
                            // }},

                        ]],
                        data:datai,
                        singleSelect:true
                    })
                }else{
                    console.log("进入流转记录·········································");
                    console.log(datai)
                    $(".liuzhuanjilu").datagrid({
                        columns:[[
                            {field: 'createrName', title: '操作人', align: 'center'},
                            {field: 'createrDepartmentName', title: '所属机构', align: 'center'},
                            {field: 'lastestTime', title: '操作时间', align: 'center',formatter: function (value) {
                        return formatData(value)
                    }},
                            // {field: 'flowTypeName', title: '处理时间', align: 'center'},
                            {field: 'flowTypeName', title: '流转类型', align: 'center'},
                            {field: 'handlerInfo', title: '备注', align: 'center'},

                        ]],
                        data:datai,
                        singleSelect:true
                    })
                }
            }
        }
    })
}
$(function () {
    // 重写验证规则
    $.extend($.fn.validatebox.defaults.rules, {
        testnames: {
            validator: function(value, param){
                console.log(value)
                var reg = /^[\u4e00-\u9fa5_a-zA-Z0-9]+$/;
                return reg.test(value);
            },
            message: '只能输入汉字，字母和数字'
        }
    });


    $("#tttabs").tabs({
        border:false,
        onSelect:function(title,index){
            console.log(title)
            if(title == '处理记录'){
                gdjl(1)
            }else{
                gdjl(2)

            }
        }
    });
    $(".pointSapan").click(function () {
        var key = $(this).attr("name");
        $.ajax({
            url:G_CTX_PATH +'/ccos/org/getwebpointsforworkorder.do',
            data:{
                point: key,
                orgType: 20,
                page: 1,
                rows: 10,
            },
            success:function (data) {
                console.log(data);
                if(data.success){
                    if(!data.rows||data.rows.length == 0){
                        // showInfoMsg("没有查询到网点信息");
                        icsOpenDialog('sendMessageDialog','发送短信',300);
                        $('#sendPhone').textbox('setValue',$('#customerTel').val());
                        $("#sendContent").textbox("setValue","");
                        return;
                    }
                    var code = data.rows[0].deptCode;
                    $.ajax({
                        url:G_CTX_PATH +'/ccos/org/queryDetial.do',
                        data:{
                            deptCode:code
                        },
                        success:function (e) {
                            console.log(e);
                            if(e.success){
                                var sg=e.data
                                var text = "网点名称："+sg.deptName+" " +
                                    "网点编码："+sg.deptCode+" " +
                                    "网点地址："+sg.detailAddress+" " +
                                    "网点电话："+sg.servicePhone
                                icsOpenDialog('sendMessageDialog','发送短信',300);
                                $('#sendPhone').textbox('setValue',$('#customerTel').val());
                                $("#sendContent").textbox("setValue",text);
                            }else{
                                showInfoMsg("没有查询到网点信息")
                            }
                        }

                    })
                }
            }
        })
    })
    // uceDictCombobox("custSex", "SYS_SEX",param);
    intcombogrid('xxdutyWebsite',changeFun);
    intcombogrid('wdmsg',changeFun);
    // 报价
    $("#bjc").click(function () {
        console.log($(this).is(':checked'));
        var isCheck = $(this).is(':checked');
        $("#bji").textbox({
            disabled:!isCheck,
            required:isCheck
        })
    })
    // 代收
    $("#dsc").click(function () {
        console.log($(this).is(':checked'));
        var isCheck = $(this).is(':checked');
        $("#dsi").textbox({
            disabled:!isCheck,
            required:isCheck
        })
    })
    //体积计算
    $("#tj").textbox({
        onClickButton:function () {
            var h = $("#hight").textbox("getValue");
            var w = $("#width").textbox("getValue");
            var l = $("#long").textbox("getValue");
            $(this).textbox("setValue",(h*w*l/1000).toFixed(2))
        }
    })

    // 运单信息折叠面板
    $("#accordion").accordion({
        onSelect:function (title,index) {
            console.log(title,index);
            console.log(title,index);
            var status = billData.goodsInfoVo.transStatus
            billData.goodsInfoVo.transStatus = status=="1"?"已转":status=="2"?"未转":"";
            billData.goodsInfoVo.issign = billData.goodsInfoVo.issign==true?"是":billData.goodsInfoVo.issign==false?"否":"";
            billData.wayBillInfoVo.manMarkName = billData.wayBillInfoVo.manMarkName==0?"否":billData.wayBillInfoVo.manMarkName==1?"是":"";

            if(index == 0){
                for(var i =0;i<$(".ydxxtable0 td").length;i++){
                    var key=$(".ydxxtable0 td").eq(i).attr("id");
                    $(".ydxxtable0 td").eq(i).text(billData.wayBillInfoVo[key]?billData.wayBillInfoVo[key]:"")
                }
            }else if(index == 1){
                for(var i =0;i<$(".ydxxtable1 td").length;i++){
                    var key=$(".ydxxtable1 td").eq(i).attr("class");
                    $(".ydxxtable1 td").eq(i).text(billData.goodsInfoVo[key]?billData.goodsInfoVo[key]:"")
                }
            }else if(index == 2){
                var dom = $(".ydxxtable2 td");
                var msgdata = billData.settleInfoVo;
                for(var i =0;i<dom.length;i++){
                    var key=dom.eq(i).attr("class");
                    dom.eq(i).text(msgdata[key]?msgdata[key]:"")
                }
            }else if(index == 3){
                var dom = $(".ydxxtable3 td");
                var msgdata = billData.vaInfoVo;
                for(var i =0;i<dom.length;i++){
                    var key=dom.eq(i).attr("class");
                    dom.eq(i).text(msgdata[key]?msgdata[key]:"")
                }
            }else if(index == 4){
                var dom = $(".ydxxtable4 td");
                var msgdata = billData.wayBillInfoVo;
                for(var i =0;i<dom.length;i++){
                    var key=dom.eq(i).attr("class");
                    dom.eq(i).text(msgdata[key]?msgdata[key]:"")
                }
            }
        },
        onUnselect:function (title,index) {

        }
    });
    $("#accordion").accordion('getSelected').panel('collapse')
    //解决右側tab切换时，点击搜索，导致列表不展示
    $('#rightWaybillTab').tabs({
        onSelect:function(title,index){
            console.log(title)
            //重设表格
            if(title=="物流信息"){
                $("#logisticsInformationDataGrid").datagrid("resize");
            }else if(title=="运单信息"){

            }else if(title=="运单信息变更"){
                $("#childInformationDataGrid").datagrid('loadData', { total: 0, rows: [] })
                $.ajax({
                    url:apiUrl+"/ccos/waybill/waybillproblem.do",
                    data:{
                        wayNum:"103469371015"
                    },
                    success:function (e) {
                        if(e.success){
                            $("#childInformationDataGrid").datagrid({
                                data:e.data,
                                columns:[[
                                    {field:'changeContent',title: '变更内容',align: 'center'},
                                    {field:'changer',title: '创建人',align: 'center'},
                                    {field:'changeTime',title: '创建时间',align: 'center'},

                                ]]
                            })
                        }
                    }

                })
            }else if(title=="代收货款"){
                $("#dshkgrid").datagrid('loadData', { total: 0, rows: [] })
                $.ajax({
                    url:apiUrl+"/ccos/waybill/receiptmoney.do",
                    data:{
                        // waybill:twaybillNum
                        wayNum:'103469363070'
                    },
                    success:function (e) {
                        console.log(e);
                        if(e.success){
                            // var data = JSON.parse(e.message);
                            // data.receiptmoneyVo
                            // console.log(data);
                            $("#dshkgrid").datagrid({
                                data:e.data,
                                nowrap:false,
                                columns:[[
                                    {field:'operateTypeName',title: '操作类型',align: 'center'},
                                    {field:'operateContent', title: '内容',align: 'center'},
                                    {field:'operateTime',width:'80px',title: '操作时间',align: 'center'},
                                    {field:'operater',title: '操作人',align: 'center'},
                                    {field:'operateCom',title: '所属公司',align: 'center'},
                                ]]
                            })
                        }
                    }

                })
            }
        }

    });
    //加载数据字典项
    var params = {
        url: G_CTX_PATH + "/dictData/findByTypesCodes.do"
    };
    initDictDatas("PRCESS_PRIORITY_PROCESSING,CUSTOMER_GRADE,CUSTOMER_TYPE,CUSTOMER_IDENTITY,SYS_SEX" +
        ",CUST_SER_STATUS,CUST_SER_PAYMENT", params);
    //去除header opotion
    var param={
        headerValue:false
    }
    //客户信息初始化开始

    //初始化客户性别
       uceDictCombobox("custSex", "SYS_SEX",param);
    //客户等级 、客户类型给默认值2018-07-18
    var valueParam={
        headerValue:false,
        value:"0"
    }
    //初始化客户等级
    uceDictCombobox("custGrade", "CUSTOMER_GRADE",valueParam);
    //初始化客户类型
//        uceDictCombobox("custType", "CUSTOMER_TYPE",valueParam);
       uceDictCombobox("custType", "CUSTOMER_TYPE",valueParam);
//     combobAjax('custType',"/cs/CsSmOrderType/getCustomerType.do")
//        责任环节
    combobAjax('zrhj',"/cs/CsSmOrderType/getResponsibilityLink.do")
    //回电时效
    combobAjax("hdsx","/cs/CsSmOrderType/getReCallTime.do")
    //初始化省、市、区、乡镇
    var areaparams={editable:true};
    //初始化发件地址省、市、区、乡镇
    newpcrtAreaCascade("province","city","county","town",areaparams);
    //客户信息初始化结束

    //工单信息初始化开始
    //初始化优先级
    uceDictCombobox("priority", "PRCESS_PRIORITY_PROCESSING",param);
    //初始客户身份
    uceDictCombobox("customerIdentity", "CUSTOMER_IDENTITY",param);
    //初始付款方式
    uceDictCombobox("payType", "CUST_SER_PAYMENT",{headerValue:false});
    //初始化工单类型/工单子类型
    var orderTypeParam = {
        url:G_CTX_PATH+"/cs/CsSmOrderType/queryComplaintTypeConf.do",
        data:{
            parentId:0
        },
        childUserMethod:orderChildTypeSelect,
        onSelect: function (param) {
            if(param.name == "下单"){
                setRequires(["sender","senderTel","sendProvince","sendCity","sendAddress",
                    "receiver","receiverTel","receiveProvince","receiveCity","receiveAddress",
                    "expressInterior","qty","goodsWeight","payType","waybillNum"]);
                unSetRequires(["priority","customerIdentity"]);
                $("#orderRemark").textbox({validType:['length[0,128]'] });
                $("#qty").textbox("setValue",1);
                $("#goodsWeight").textbox("setValue",0.5);
                $("#payType").combobox("setValue",1);
            }else{
                unSetRequires(["sender","senderTel","sendProvince","sendCity","sendAddress",
                    "receiver","receiverTel","receiveProvince","receiveCity","receiveAddress",
                    "expressInterior","qty","goodsWeight","payType"]);
                setRequires(["priority","customerIdentity","waybillNum"]);
                $("#orderRemark").textbox({validType:['length[0,500]'] });
                $("#qty").textbox("setValue",null);
                $("#goodsWeight").textbox("setValue",null);
                $("#payType").combobox("setValue",null);
                $("#gotTime").combobox("setValue",null);
                $("#gotTime_ref").combobox("setValue",null);
                unSetRequires(["gotTime_ref"]);
            }

        }
    };
//        setCsSmOrderTypeSelect("orderType", "orderChilType",orderTypeParam);
    combobAjax("neworderType","/cs/CsSmOrderType/queryComplaintTypeConf.do",{parentId:0},gdlxFun,{key:"causeType",value:"complaintTypeConfId"});
    function gdlxFun(n,o) {
        console.log(n,o);
        setRequires(["zrhj","hdsx","neworderChilType"])
        //判断是否下单
        if(n == 36){
            $(".xd").show();
            $(".nxd").hide();
            unSetRequires(["zrhj","hdsx","neworderChilType"])
        }else{
            $(".xd").hide();
            $(".nxd").show();
        }
        combobAjax("neworderChilType","/cs/CsSmOrderType/queryComplaintTypeConf.do",{parentId:n},null,{key:"causeType",value:"complaintTypeConfId"})
    }
    //初始化发件省、市、区、乡镇
    newpcrtAreaCascade("sendProvince","sendCity","sendArea","sendTown",areaparams);

    //初始化收件省、市、区、乡镇
    newpcrtAreaCascade("receiveProvince","receiveCity","receiveArea","receiveTown",areaparams);
    //工单信息初始化结束
    //加载页面信息
    if(customerPhone){
        $("#custSerForm #customerTelSearch").val(customerPhone);
        queryComprehensiveInformation(customerPhone,"",'CustomerTelSearch');

    }

    //初始化责任网点2018-09-18
    // initDutyWebsiteCombobx();

    //初始化预约时间
    initGotTime();

});

// 网点查询链接
function wdcxlj(type) {
    console.log(type)
    if(type==0){
        console.log("8888")
        var provinceName = $("#sendProvince").combobox("getText");
        var sendProvince = $("#sendProvince").combobox("getValue");
        var cityName =$("#sendCity").combobox("getText")
        var sendCity =$("#sendCity").combobox("getValue")
        var regionName =$("#sendArea").combobox("getText")
        var deliverStreetName =$("#sendTown").combobox("getText")
        var street = $("#sendAddress1").textbox("getValue")
        if(!sendProvince||!sendCity||!regionName||!street){
            showInfoMsg("请确保省、市、区、详细地址都已填写")
            // $.messager.show({
            //     title:'My Title',
            //     msg:'The message content',
            //     showType:'fade',
            //     style:{
            //         right:'',
            //         bottom:''
            //     }
            // });
            return
        }
        var url =
            "https://yh.yimidida.com/galaxy-gis-business/map/searchNetwork?provinceCode=" +
            sendProvince +
            "&cityCode="+sendCity+
            "&compCode=yimidida"+
            "&provinceName=" +
            encodeURI(provinceName) +
            "&cityName=" +
            encodeURI(cityName) +
            "&dictName=" +
            encodeURI(regionName) +
            "&addressInfo=" +
            encodeURI(deliverStreetName + street) +
            "&addressName=" +
            encodeURI(provinceName + cityName + regionName) +
            "&bizType=2&__showUrl=true&version=201503191844";
        window.open(url,'_blank');
        openTabCrossDomainForWlgj("","查询网点",url,true,0);
    }else{
        var provinceName = $("#receiveProvince").combobox("getText");
        var cityName =$("#receiveCity").combobox("getText")
        var regionName =$("#receiveArea").combobox("getText")
        var deliverStreetName =$("#receiveTown").combobox("getText")
        var street = $("#receiveAddress1").textbox("getValue")
        var sendProvince = $("#receiveProvince").combobox("getValue");
        var sendCity = $("#receiveCity").combobox("getValue");
        if(!sendProvince||!sendCity||!regionName||!street){
            showInfoMsg("请确保省、市、区、详细地址都已填写")
            return
        }
        var url =
            "https://yh.yimidida.com/galaxy-gis-business/map/searchNetwork?provinceCode=" +
            sendProvince +
            "&cityCode="+sendCity+
            "&compCode=yimidida"+
            "&provinceName=" +
            encodeURI(provinceName) +
            "&cityName=" +
            encodeURI(cityName) +
            "&dictName=" +
            encodeURI(regionName) +
            "&addressInfo=" +
            encodeURI(deliverStreetName + street) +
            "&addressName=" +
            encodeURI(provinceName + cityName + regionName) +
            "&bizType=2&__showUrl=true&version=201503191844";
        openTabCrossDomainForWlgj("","查询网点",url,true,0);
    }
}
/**
 * 时间段获取
 * @param num 当前几点
 * @param limit 截至几点
 * @param gotDate 预约日期
 * @returns {*[]}
 */
function getGotTimeData(num,limit,gotDate){
    try {
        if(gotDate == undefined){
            throw new Error("预约日期undefind");
        }
        var data = [];
        //var nowDate = new Date().format("yyyy-MM-dd hh:00:00");
        if(num == limit){
            return data;
        }
        while (num < limit) {
            var json = {};
            if (num < 10) {
                json["idStr"] = "0" + num;
                json["name"] = "0" + num + ":00-" + (Number(num) + 1) + ":00";
                json["star"] = gotDate + " 0" + num + ":00:00";
                json["end"] = gotDate + " " + (Number(num) + 1) + ":00:00";
            } else {
                json["idStr"] = num;
                json["name"] = num + ":00-" + (Number(num) + 1) + ":00";
                json["star"] = gotDate + " " + num + ":00:00";
                json["end"] = gotDate + " " + (Number(num) + 1) + ":00:00";
            }
            data.push(json);
            num++;
        }
    } catch (e) {
        console.error("预约时间异常:"+e);
    }
    return data;
}

function addDate(day){
    var date = new Date();
    date = date.DateAdd("d",day);
    return date.format("yyyy-MM-dd");
}

/**
 * 初始化预约时间段
 */
function initGotTime(){
    //预约时间
    $("#gotTime").combobox({
        onSelect:function(node){
            var gotDate = node.idStr;
            if(gotDate == ""){
                $("#gotTime_ref").combobox("loadData",[]);
                $("#gotTime_ref").combobox("clear");
                $("#gotBeginTime").val(null);
                $("#gotEndTime").val(null);
            }else if(node.name == "今天"){
                var hour = new Date().DateAdd("h",1).format("hh");
                data = getGotTimeData(hour,20, gotDate);
                $("#gotTime_ref").combobox("loadData",data);
            }else {
                data = getGotTimeData(9,20,gotDate);
                $("#gotTime_ref").combobox("loadData",data);
            }
            if(node.idStr != null && node.idStr != ""){
                //选了时间时间段必须要选择
                setRequires(["gotTime_ref"]);
            }else{
                unSetRequires(["gotTime_ref"]);
            }

        }
    })

    var date = new Date();
    $("#gotTime").combobox("loadData",[
        {idStr:"",name:"请选择预约时间",selected:true},
        {idStr:date.format("yyyy-MM-dd"),name:"今天"},
        {idStr:addDate(1),name:"明天"},
        {idStr:addDate(2),name:"后天"}
    ]);
    var data = [];

    //预约时间段
    $("#gotTime_ref").combobox({
        onShowPanel:function(node){
            if($("#gotTime").combobox("getText") == "今天"){
                var gotDate = $("#gotTime").combobox("getValue");
                var hour = new Date().DateAdd("h",1).format("hh");
                data = getGotTimeData(hour,20,gotDate);
                $(this).combobox("loadData",data,"");
            }
        },
        onSelect:function(node){
            $("#gotBeginTime").val(node["star"]);
            $("#gotEndTime").val(node["end"]);
        }
    });
}

/**
 * 根据来电号码综合查询
 * */
function queryComprehensiveInformationByCustomerTel(){
    var customerTel;
    var waybillNum;
    console.log('ssss')

    console.log(customerTel)
    if($("#customerTel").textbox('isValid')){
        customerTel =$("#customerTel").val();
        waybillNum =$("#waybillNum").val();
        if(waybillNum){
            if($("#waybillNum").textbox('isValid')){

            }else{
                /*window.parent.rlliu*/showInfoMsg("请输入正确的运单号");
                return;
            }
        }
        queryComprehensiveInformation(customerTel,waybillNum,'CustomerTelSearch');
    }else{
        /*window.parent.rlliu*/showInfoMsg("请输入正确的来电号码");
        return;
    }

}

/**
 * 根据运单号综合查询
 * */
function queryComprehensiveInformationByWaybillNum(){
    var waybillNum =$("#waybillNum").val();
    var tel = $("#customerTel").textbox("getValue");
    // $("#gdForm").form("reset");
    $(".dzxxf").form("reset");
    $("#waybillNum").textbox("setValue",waybillNum);
    $("#customerTel").textbox("setValue",tel)
    // $("")
    // var waybillNum="103469408765"
    var customerTel;
    if(waybillNum){
        if($("#waybillNum").textbox('isValid')){
            customerTel =$("#customerTel").val();
            if(customerTel){
                if($("#customerTel").textbox('isValid')){

                }else{
                    /*window.parent.rlliu*/showInfoMsg("请输入正确的来电号码");
                    return;
                }
            }
            // 运单信息
            $('#newlogisticsInformationDataGrid').datagrid('loadData', { total: 0, rows: [] })
            $.ajax({
                url:apiUrl+"/ccos/waybill/wayBillInfo.do",
                data:{
                    wayNum:waybillNum,
                },
                success:function (e) {
                    console.log(e);
                    if(e.success){
                        billData = e.data;
                        var info = e.data.wayBillInfoVo;
                        $(".wd").show()
                        if(!info){
                            console.error("没有获取到运单信息！")
                            return;
                        }
                        $(".startPoint").text(info.startPoint+' '+ info.startPointPhone);
                        $(".startPoint").attr("name",info.startPoint)
                        $(".endPoint").text(info.endPoint+' '+ info.endPointPhone);
                        $(".endPoint").attr("name",info.endPoint);
                        var routeInfo = e.data.routingLocusInfo;
                        var cusInfoVo = e.data.cusInfoVo;
                        console.log(cusInfoVo)
                        $(".dzxxf").form("load",cusInfoVo)
                        $('#newlogisticsInformationDataGrid').datagrid({
                            data: routeInfo,
                            columns:[[
                                {field:'operateTime',title: '操作时间',align: 'center'},
                                {field:'operateDep',title: '操作部门',align: 'center'},
                                {field:'nextDep',title: '下一部门',align: 'center'},
                                {field:'operateTypeName',title: '操作类型',align: 'center'},
                                {field:'operater',title: '操作人',align: 'center'},
                                {field:'scanNum',title: '扫描件数',align: 'center'},
                            ]],
                            fitColumns : 'true'
                        });
                        //

                    }
                }
            });
            // 运单信息
            $.ajax({
                url:apiUrl+"/ccos/waybill/getWayBillInfoDetail.do",
                data:{
                    wayNum:waybillNum,
                },
                success:function (e) {
                    console.log(e)
                    billData2 = e.data;
                    $("#gdForm").form("load",e.data);
                    $(".routeName").text(e.data.routeName);
                }
            });
            // 问题件查询
            $("#newproblemInformationDataGrid").datagrid('loadData', { total: 0, rows: [] })
            $.ajax({
                url:apiUrl+"/ccos/waybill/problemInfo.do",
                data:{
                    waybill:waybillNum,
                },
                success:function (data) {
                    console.log(data);
                    if(data.success){
                        $("#newproblemInformationDataGrid").datagrid({
                            data: data.data,
                            columns:[[
                                {field:'problemNum',title: '问题件编码',align: 'center',formatter:function (value,row,index) {
                                    return "<a onclick=showWTdeta('"+value+"')>"+value+"</a>"
                                }},
                                {field:'problemStatus',title: '问题件状态',align: 'center'},
                                {field:'problemType',title: '问题类别',align: 'center'},
                                {field:'replyContent',title: '回复内容',align: 'center'},
                                {field:'problemDetil',title: '问题详情',align: 'center'},
                                {field:'replyer',title: '回复人',align: 'center'},
                                {field:'reporter',title: '上报人',align: 'center'},
                                {field:'reportTime',title: '上报时间',align: 'center'},
                                {field:'businessType',title: '经营属性',align: 'center'}
                            ]],
                            fitColumns : 'true',
                            singleSelect:true,
                        });
                        // $("#accordion").accordion('getSelected').panel('collapse')
                    }
                }
            })
            $("#wtjp").accordion({
                onSelect:function (a,b,c) {
                    console.log(3)
                }
            })
            // 工单
            ajaxGD(waybillNum)

        }else{
            /*window.parent.rlliu*/showInfoMsg("请输入正确的运单号");
            return;
        }
    }else{
        /*window.parent.rlliu*/showInfoMsg("请输入正确的运单号");
        return;
    }

}
/**
 * 根据运单号和来电号码综合查询
 * searchType: CustomerTelSearch 来电号码查询
 *             waybillNumSearch  运单号查询
 * */
//入口初始化
function queryComprehensiveInformation(customerTel,waybillNum,searchType){
    console.log("ss123123")
    if(customerTel||waybillNum){
        var data={};
        if(customerTel){
            console.log(customerTel)
            data.customerTel=customerTel;
            //加载客户信息
            if(searchType=="CustomerTelSearch"){
                queryCustomerInformation(customerTel);
            }
        }
        if(waybillNum){
            data.waybillNum=waybillNum;
            if(searchType=="waybillNumSearch"){
                //物流信息列表
                newinitLogisticsInformationDataGrid(waybillNum);
                //问题信息列表
                newinitProblemInformationDataGrid(waybillNum);
                //运单信息查询
                initWaybillInformation(waybillNum);
                //发放记录列表
                initRecordsInformationDataGrid(waybillNum);
                //子单信息列表
                initChildInformationDataGrid(waybillNum);
            }
            var url = G_CTX_PATH+"/dictData/findByTypesCodes.do";
            initDictDatas("BILL_TRACE_LINK",{url:url});
            var LINKURL = "URL";
            var OPENSWITCH = "SWITCH";
            var OPENSWITCH= getTypeNameByCode("BILL_TRACE_LINK",OPENSWITCH,null);
            var link= getTypeNameByCode("BILL_TRACE_LINK",LINKURL,null);
            //开关开启
            // if (OPENSWITCH != null && OPENSWITCH == 1 && link!= null && link != '' && link != undefined){
            //     openTabCrossDomainForWlgj("csProblemOrder_add","快件跟踪-"+waybillNum,link+waybillNum,true,0,portal_global_systemCode,true);
            // }else{
            //     //  openTabCrossDomainIcsSimple("wayBill_infomation","查运单","/cs/wayBill/infomation.do?waybillNum="+waybillNum,true,0,portal_global_systemCode,true);
            // }
        }
        //处理中工单列表
        initProcessingCustSerOrderDataGrid(customerTel,waybillNum);
        //处理完成工单列表
        initFinishedCustSerOrderDataGrid(customerTel,waybillNum);
    }else{
        return;
    }
}
/***
 * 处理中工单列表加载功能区域
 * **/
function ajaxGD(bill) {
    try {
        $("#newprocessingCustSerOrderDataGrid").datagrid('loadData', { total: 0, rows: [] })
        $("#ywjgdTable").datagrid('loadData', { total: 0, rows: [] })
    }catch (e){
        console.log(e)
    }

    $.ajax({
        url: apiUrl + "/ccos/workOrder/getHistoryWorkOrder.do",
        data: {
            wayBillNo: bill
        },
        success: function (e) {
            console.log(e);
            if (e.success) {
                if (e.data.processedList) {
                    console.table(e)
                    gdIng = e.data.processedList;
                    $("#processingCustSerOrderNum").html(gdIng.length?gdIng.length:0);
                    // $(".newcl").show();
                    // $(".oldcl").hide();
                    $("#newprocessingCustSerOrderDataGrid").datagrid({
                        columns:[[
                            {field: 'workBillNo', title: '工单编号', align: 'center', formatter: function (value,row,index) {
                                return "<a href='javascript:void(0)' onclick='showGdDet(0,"+index+")'>"+value+"</a>"
                            }
                            },
                            {field: 'complaintBigTypeName', title: '投诉大类', align: 'center'},
                            {field: 'complaintLittleTypeName', title: '投诉小类', align: 'center'},
                            {field: 'handleDepartmentName', title: '任务部门', align: 'center'},
                            {field: 'repeatComplaintCount', title: '投诉次数', align: 'center'},
                            {field: 'handleTime', title: '最近处理时间', align: 'center',formatter: function (value) {
                                return formatData(value)
                            }},
                            {field: 'billStatusName', title: '工单状态', align: 'center'},
                            {field: 'createrTime', title: '创建时间', align: 'center',formatter: function (value) {
                                return formatData(value)
                            }},
                        ]],
                        data:e.data.processedList,
                        rownumbers:true,
                        rownumberWidth:30,
                        fitColumns:false,
                        singleSelect:true
                    })

                }
                if (e.data.finishList) {
                    gdEd = e.data.finishList;
                    console.table(gdEd)
                    $("#finishedCustSerOrderNum").html(e.data.finishList.length?e.data.finishList.length:0);
                    $("#childInformationDataGrid").datagrid('loadData', { total: 0, rows: [] })
                    $("#ywjgdTable").datagrid({
                        columns:[[
                            {field: 'workBillNo', title: '工单编号', align: 'center', formatter: function (value,row,index) {
                                return "<a href='javascript:void(0)' onclick='showGdDet(1,"+index+")'>"+value+"</a>"
                            }
                            },
                            {field: 'complaintBigTypeName', title: '投诉大类', align: 'center'},
                            {field: 'complaintLittleTypeName', title: '投诉小类', align: 'center'},
                            {field: 'handleDepartmentName', title: '任务部门', align: 'center'},
                            {field: 'repeatComplaintCount', title: '投诉次数', align: 'center'},
                            {field: 'handleTime', title: '最近处理时间', align: 'center',formatter: function (value) {
                                return formatData(value)
                            }},
                            {field: 'billStatusName', title: '工单状态', align: 'center'},
                            {field: 'createrTime', title: '创建时间', align: 'center',formatter: function (value) {
                                return formatData(value)
                            }},
                        ]],
                        data:e.data.finishList,
                        rownumbers:true,
                        rownumberWidth:30,
                        fitColumns:false,
                        singleSelect:true
                    })
                }
            }
        }
    })
}
function initProcessingCustSerOrderDataGrid(customerTel,waybillNum) {
    //处理中工单必要参数
    var processingParams={};
    if(customerTel)
        processingParams.customerTel=customerTel;
    if(waybillNum){
        processingParams.waybillNum=waybillNum;
    }
    processingParams.statusMul="0,1,2,3,4";
    processingParams.source="0";
    var columns = [[
        {field: 'ck', checkbox: true, resizable: true, align: 'center'},
        {
            field: 'deal', title: '操作', align: 'center',formatter: function (value, row, index) {
            var ret = '<a href="javascript:void(0)" title="预览" class="icon-search" data-options="plain:true,iconCls:\'icon-search\'" onclick="dlgCsWorkOrder(\''+index+'\',\'processingCustSerOrderDataGrid\')"></a>';
            return ret;
        }
        },
        {field: 'code', title: '工单编号', align: 'center',formatter: formatTip},
        {field: 'waybillNum', title: '运单编号', align: 'center', formatter: formatTip3},
        {
            field: 'priority', title: '优先级', align: 'center',width:50, formatter: function (value) {
            return getTypeNameByCode("PRCESS_PRIORITY_PROCESSING", value, formatTip);
        }
        },
        {field: 'urgeNum', title: '催办次数', align: 'center',width:60, formatter: formatTip},
        {
            field: 'status', title: '状态', align: 'center',width:100, formatter: function (value) {
            return getTypeNameByCode("CUST_SER_STATUS", value, formatTip);
        }
        },
        {field: 'orderTypeName', title: '工单类型', align: 'center',width:60,formatter: formatTip},
        {field: 'orderChilTypeName', title: '工单子类型', align: 'center',width:80, formatter: formatTip},
        {field : 'dutyDepartBaseName',title : '责任网点(初判)',align:'center',width:100,formatter: formatTip},
        {field: 'submitterName', title: '工单发起人', align: 'center',width:100, formatter: formatTip},
        {field: 'currentDealEmpName', title: '受理人', align: 'center',width:120, formatter: formatTip},
        {
            field: 'createTime', title: '创建时间', align: 'center',width:200,formatter: function (value) {
            return formatData(value)
        }
        }

    ]];
    var dataGridParams = {
        url: G_CTX_PATH + "/cs/CsWoCustSer/getCsWoCustSerVoList.do",
        queryParams: processingParams,
        fitColumns: 'false',
        rownumbers: 'false',
        singleSelect: 'true',
        pageSize : 10,
        onLoadSuccess: function (param) {
            $('.icon-search').linkbutton({plain:true,iconCls:'icon-search'});
            $("#processingCustSerOrderNum").html(param.total);
            //存在处理中工单时，切换到处理中工单页面 2018-07-17
            if (param.total > 0) {
                $('#leftCsSmOrdeTab').tabs('select',1);
            }
        }
    };
    // newloadGrid('processingCustSerOrderDataGrid', columns, dataGridParams);
}

/***
 * 已完结工单列表加载功能区域
 * **/
function initFinishedCustSerOrderDataGrid(customerTel,waybillNum) {
    //已完结工单必要参数
    var finishedParams={};
    if(customerTel)
        finishedParams.customerTel=customerTel;
    if(waybillNum){
        finishedParams.waybillNum=waybillNum;
    }
    finishedParams.status= "5";
    finishedParams.source="0";
    var columns = [[
        {field: 'ck', checkbox: true, resizable: true, align: 'center'},
        {
            field: 'deal', title: '操作', align: 'center', formatter: function (value, row, index) {
            //预览方法查询工单流程信息
            var ret = '<a href="javascript:void(0)"  title="预览" class="easyui-linkbutton icon-search" data-options="plain:true,iconCls:\'icon-search\'" onclick="dlgCsWorkOrder(\''+index+'\',\'finishedCustSerOrderDataGrid\')"></a>';
            return ret;
        }
        },
        {field: 'code', title: '工单编号', align: 'center', formatter: formatTip},
        {field: 'waybillNum', title: '运单编号', align: 'center', formatter: formatTip3},
        {
            field: 'priority', title: '优先级', align: 'center',width:50, formatter: function (value) {
            return getTypeNameByCode("PRCESS_PRIORITY_PROCESSING", value, formatTip);
        }
        },
        {field: 'urgeNum', title: '催办次数', align: 'center',width:60, formatter: formatTip},
        {
            field: 'status', title: '状态', align: 'center',width:100,formatter: function (value) {
            return getTypeNameByCode("CUST_SER_STATUS", value, formatTip);
        }
        },
        {field: 'orderTypeName', title: '工单类型', align: 'center', width:60,  formatter: formatTip},
        {field: 'orderChilTypeName', title: '工单子类型', align: 'center', width:80, formatter: formatTip},
        {field : 'dutyDepartBaseName',title : '责任网点(初判)',align:'center',width:100,formatter: formatTip},
        {field: 'submitterName', title: '工单发起人', align: 'center', width:100, formatter: formatTip},
        {field: 'currentDealEmpName', title: '受理人', align: 'center', width:120, formatter: formatTip},
        {
            field: 'createTime', title: '创建时间', align: 'center',width:200,formatter: function (value) {
            return formatData(value)
        }
        }

    ]];

    var dataGridParams = {
        url: G_CTX_PATH + "/cs/CsWoCustSer/getCsWoCustSerVoList.do",
        queryParams: finishedParams,
        fitColumns: 'false',
        rownumbers: 'false',
        singleSelect: 'true',
        pageSize : 10,
        onLoadSuccess: function (param) {
            $('.icon-search').linkbutton({plain:true,iconCls:'icon-search'});
            $("#finishedCustSerOrderNum").html(param.total);
        },

    };
    // newloadGrid('finishedCustSerOrderDataGrid', columns, dataGridParams);
}

/***
 * 处理中工单和已完结工单
 *详情页
 * **/
function dlgCsWorkOrder(index,dataGridId){
    var rows = $("#"+dataGridId).datagrid("getData").rows;
    var row = rows[index];
    var id =row.idStr;
    var woCode =row.woCode;
    var url = G_CTX_PATH+"/dictData/findByTypesCodes.do";
    initDictDatas("ICS_CUSTSER_URL",{url:url});
    var ser= getTypeNameByCode("ICS_CUSTSER_URL","url",null);
    openTabCrossDomainForWlgj("csWoCustSer_detail","客服服务类工单详情",ser+id+"/view/"+woCode+"/0/.do",true,0,portal_global_systemCode,true);
}
/**
 * 客户信息查询
 */
function queryCustomerInformation(customerTel){
    if(customerTel){
        var url =G_CTX_PATH+'/cs/CsCustomerInfomation/getCustomerInformationQueryPhone.do';
        uceAjax(url,{phone:customerTel},function(result){
            if(result.success){
                //来电号码
                $('#custSerForm #customerTelSearch').val(customerTel);
                //判断当前来电号码客户信息是否存在
                if(result.data!=null){
                    //来电客户信息存在
                    setCustomerInformation(result.data);
                }else{
                    //来电手机号客户信息不存在
                    //没有客户信息，清空表单数据
                    clearForm("customerInformationForm");
                    setCustomerCode();//设置客户信息区域客户编码
                    //初始值 2018-07-18
                    $('#customerInformationForm #custGrade').combobox('setValue', "0");//客户等级
                    console.log($('#customerInformationForm #custType').combobox('getData'))
                    $('#customerInformationForm #custType').combobox('setValue', "1");//客户类型

                }
            }
        });
    }

}
/**
 *客户信息
 * */
function setCustomerInformation(data) {
    if (data != null) {
        //设置客户信息值
        $('#customerInformationForm #id').val(data.id);//客户id
        if(data.custCode!=null)
            $('#customerInformationForm #custCode').textbox('setValue', data.custCode);//客户编码
        if(data.custSex!=null)
            $('#customerInformationForm #custSex').combobox('setValue',  ""+data.custSex+"");//客户性别
        if(data.custName!=null)
            $('#customerInformationForm #custName').textbox('setValue',  ""+data.custName+"");//客户名称
        if(data.custGrade!=null)
            $('#customerInformationForm #custGrade').combobox('setValue', ""+data.custGrade+"");//客户等级
        if(data.custType!=null)
            //000000
            $('#customerInformationForm #custType').combobox('setValue', ""+data.custType+"");//客户类型
        if(data.custLabel!=null)
            $('#customerInformationForm #custLabel').textbox('setValue', data.custLabel);//客户标签
        var params={
            provinceValue:data.province,
            cityValue:data.city,
            regionValue:data.county,
            townValue:data.town
        }
        newpcrtAreaCascade("province", "city", "county","town",params);
        if(data.address)
            $('#customerInformationForm #address').textbox('setValue', data.address);//客户详细地址

    }
}
/***
 * 无对应客户信息时，设置客户信息编码
 * 设置客户编码值方法功能区域
 * **/
function setCustomerCode() {
    var url = G_CTX_PATH + '/cs/HomeScreenPopup/getCustomer.do';
    $.ajax({
        type: 'get',
        url: url,
        success: function (data) {
            //2018-08-30
            if(data.Customer){
                $('#customerInformationForm #custCode').textbox('setValue', data.Customer);//客户编码
            }
        }
    });
}
/*
 * 物流信息列表加载
 * @param waybillNum 运单号
 */
// function  newinitLogisticsInformationDataGrid(waybillNum){
//     var columns = [[
//         {field:'createDate',title: '日期',align: 'center'},
//         {field:'createTime',title: '时间',align: 'center'},
//         {field:'trackMessage',title: '跟踪记录'}
//     ]]
//     var dataGridParams = {
//         url:G_CTX_PATH+"/cs/HomeScreenPopup/findTraceInfo.do",
//         Method:'POST',
//         queryParams:{billCode:waybillNum},
//         singleSelect : 'true',
//         fitColumns : 'false',
//         rownumbers: 'false'
//     }
//     newloadGrid('logisticsInformationDataGrid', columns, dataGridParams);
//     var queryParams={waybill:waybillNum,
//     }
//     var wtcolumns = [[
//         {field:'problemNum',title: '工单编号',align: 'center',
//             formatter: function(value, row, index){
//                 return '<strong class="colorjinji" onmouseover="showOrderRecords(' + value + ',this)" onmouseout="hideOrderRecords(\' + value + \',this)">'+value+'</strong>';
//             }},
//         {field:'problemType',title: '问题类别',align: 'center', formatter: formatTip},
//         {field:'replyContent',title: '回复内容', align: 'center',formatter: formatTip},
//         {field:'problemDetil',title: '问题详情',align: 'center'},
//         {field:'reportDep',title: '上报部门',align: 'center'},
//         {field:'reportTime',title: '上报时间',align: 'center', formatter: formatTime},
//     ]]
//     var wtdataGridParams = {
//         url:G_CTX_PATH+"/ccos/waybill/problemInfo.do",
//         Method:'POST',
//         queryParams:queryParams,
//         singleSelect : 'true',
//         fitColumns : 'true',
//         rownumbers: 'false'
//     }
//     newloadGrid('newproblemInformationDataGrid', wtcolumns, wtdataGridParams);
//
// }
/*
 * 问题件信息列表加载
 * @param waybillNum 运单号
 * 展示字段后三个中文无对应字段，需确认
 */
function newinitProblemInformationDataGrid(waybillNum){
    var queryParams={waybill:waybillNum,
    }
    var columns = [[
        {field:'woCode',title: '工单编号',align: 'center',
            formatter: function(value, row, index){
                return '<strong class="colorjinji" onmouseover="showOrderRecords(' + value + ',this)" onmouseout="hideOrderRecords(\' + value + \',this)">'+value+'</strong>';
            }},
        {field:'createTime',title: '时间',align: 'center', formatter: formatTime},
        {field:'orderTypeName',title: '工单类型',align: 'center', formatter: formatTip},
        {field:'orderChilTypeName',title: '工单子类型', align: 'center',formatter: formatTip},
        {field:'submitterName',title: '发起站点',align: 'center'},
        {field:'currentDealEmpName',title: '接收站点',align: 'center'},
        {field:'orderTitle',title: '内容记录',align: 'center'}
    ]]
    var dataGridParams = {
        url:G_CTX_PATH+"/ccos/waybill/problemInfo.do",
        Method:'POST',
        queryParams:queryParams,
        singleSelect : 'true',
        fitColumns : 'true',
        rownumbers: 'false'
    }
    newloadGrid('newproblemInformationDataGrid', columns, dataGridParams);
}

/**
 * 展示问题件工单处理记录
 * */
function showOrderRecords(woCode,e){
    dealRecords(woCode);
    var showbox = $("#dealRecords");
    showbox.show();
    $("#dealRecordsDataGird").datagrid("resize");
    showbox.removeClass('hidebox').addClass('showbox');
    var topval =$(e).position().top;
    showbox.css({'top':topval+100});
    clearTimeout(0);
}
/**
 * 隐藏问题件工单处理记录
 * */
function hideOrderRecords(woCode,e){
    var showbox = $("#dealRecords");
    showbox.removeClass('showbox').addClass('hidebox');
    showbox.css({'top':'-1500%'});
}
/**
 * 问题件流转记录
 */
function dealRecords(woCode){
    var columns = [[
        {field:'operationName',title: '名称',align: 'center'},
        {field:'createTime',title: '创建时间',align: 'center', formatter: formatTime},
        {field:'submitTime',title: '处理时间',align: 'center', formatter: formatTime},
        {field:'handlerDepartName',title: '处理部门',align: 'center'},
        {field:'currentHandlerName',title: '处理人',align: 'center'},
        {field:'handleExplain',title: '处理意见',align: 'center'}
    ]]
    var dataGridParams = {
        url:G_CTX_PATH+"/cs/HomeScreenPopup/findProblemRecordsInfo.do",
        Method:'POST',
        queryParams:{woCode:woCode},
        singleSelect : 'true',
        fitColumns : 'false',
        rownumbers: 'false',
        nowrap: 'false'
    }
    icsloadGrid('dealRecordsDataGird', columns, dataGridParams);
}
/*
 * 运单信息查询
 * @param waybillNum 运单号
 */
function initWaybillInformation(waybillNum){
    var data ={wayNum:waybillNum};
    var url=G_CTX_PATH+"/ccos/waybill/wayBillInfo.do";
    $('#custSerForm #waybillNumSearch').val(waybillNum);//运单号
    uceAjax(url,data,function(res){
        if(res.success){
            if(res.data!=null){
                //右侧运单信息
                $('#waybillNumId').text(waybillNum);
                res.data.sendAccSiteName == null ? $('#sendAccSiteId').text(""):$('#sendAccSiteId').text(res.data.sendAccSiteName);
                //res.data.sendupAdd == null ? $('#sendupAddId').text(""): $('#sendupAddId').text(res.data.sendupAdd);
                //res.data.signer == null ? $('#signerId').text("") :  $('#signerId').text(res.data.signer);
                res.data.billTypeName == null ? $('#billType').text("") : $('#billType').text(res.data.billTypeName);
                res.data.carriage == null ? $("#carriageId").text("") : $('#carriageId').text(res.data.carriage);
                res.data.realWeight == null ?  $('#realWeightId').text("") : $('#realWeightId').text(res.data.realWeight);
                res.data.bulkWeight == null ?  $('#bulkWeightId').text("") : $('#bulkWeightId').text(res.data.bulkWeight);
                res.data.goodsPayment == null ? $('#goodsPaymentId').text("") : $('#goodsPaymentId').text(res.data.goodsPayment);
                // res.data.signTime == null ?  $('#signTimeId').text("") :  $('#signTimeId').text(timestampToTime(res.data.signTime));
                res.data.signTimeStr == null ?  $('#signTimeId').text("") :  $('#signTimeId').text(res.data.signTimeStr);
                res.data.deliveryOrgName == null ? $('#recOrgCodeId').text("") : $('#recOrgCodeId').text(res.data.deliveryOrgName);
                res.data.sendDate == null ? $('#sendDateId').text("") : $('#sendDateId').text(timestampToTime(res.data.sendDate));
                res.data.qty == null ? $('#qtyId').text(""): $('#qtyId').text(res.data.qty);
                res.data.operateEmpName == null ? $('#operateEmpNameId').text(""): $('#operateEmpNameId').text(res.data.operateEmpName);
                res.data.signMan == null ? $('#signManId').text(""): $('#signManId').text(res.data.signMan);
                res.data.sendOrgName == null ? $('#sendOrgName').text(""): $('#sendOrgName').text(res.data.sendOrgName);

                //2018-07-17 运单信息有值，只读，不校验规则，无值，可编辑，不校验规则
                if(res.data.goodsName){
                    $("#custSerForm #expressInterior").textbox("setValue", res.data.goodsName);
                    $("#custSerForm #expressInterior").textbox('readonly',true);
                }else{
                    $("#custSerForm #expressInterior").textbox('readonly',false);
                }
                //发件人
                if(res.data.sender){
                    $("#custSerForm #sender").textbox("setValue", res.data.sender);
                    $("#custSerForm #sender").textbox('readonly',true);
                    //设置验证属性
                    $("#custSerForm #sender").textbox({validType:""});
                    //解析指定元素
                    $.parser.parse($("#custSerForm #sender"));
                }else{
                    $("#custSerForm #sender").textbox('readonly',false);
                    //设置验证属性
                    $("#custSerForm #sender").textbox({validType:"length[1,40]"});
                    //解析指定元素
                    $.parser.parse($("#custSerForm #sender"));
                }
                //发件电话
                if(res.data.senderTel){
                    $("#custSerForm #senderTel").textbox("setValue", res.data.senderTel);
                    $("#custSerForm #senderTel").textbox('readonly',true);
                    //设置验证属性
                    $("#custSerForm #senderTel").textbox({validType:""});
                    //解析指定元素
                    $.parser.parse($("#custSerForm #senderTel"));
                }else{
                    $("#custSerForm #senderTel").textbox('readonly',false);
                    //设置验证属性
                    $("#custSerForm #senderTel").textbox({validType:"phoneAndTelNum"});
                    //解析指定元素
                    $.parser.parse($("#custSerForm #senderTel"));
                }
                //初始化发件地址省、市、区、乡镇2018-07-02
                var sendParams={editable:false,
                    provinceValue:res.data.sendProvinceCode,
                    cityValue:res.data.sendCityCode,
                    regionValue:res.data.sendCountyCode
                };
                newpcrtAreaCascade("sendProvince","sendCity","sendArea","sendTown",sendParams);
                if(res.data.sendProvinceCode){
                    $("#sendProvince").combobox('readonly',true);
                }else{
                    $("#sendProvince").combobox('readonly',false);
                }
                if(res.data.sendProvinceCode && res.data.sendCityCode){
                    $("#sendCity").combobox('readonly',true);
                }else{
                    $("#sendCity").combobox('readonly',false);
                }
                if(res.data.sendProvinceCode && res.data.sendCityCode && res.data.sendCountyCode){
                    $("#sendArea").combobox('readonly',true);
                }else{
                    $("#sendArea").combobox('readonly',false);
                }

                //发件详细地址
                if(res.data.senderAddress){
                    $("#custSerForm #sendAddress").textbox("setValue", res.data.senderAddress);
                    $("#custSerForm #sendAddress").textbox('readonly',true);
                }else{
                    $("#custSerForm #sendAddress").textbox('readonly',false);
                }

                //收件人
                if(res.data.receiver){
                    $("#custSerForm #receiver").textbox("setValue", res.data.receiver);
                    $("#custSerForm #receiver").textbox('readonly',true);
                    //设置验证属性
                    $("#custSerForm #receiver").textbox({validType:""});
                    //解析指定元素
                    $.parser.parse($("#custSerForm #receiver"));
                }else{
                    $("#custSerForm #receiver").textbox('readonly',false);
                    $("#custSerForm #receiver").textbox({validType:"length[1,40]"});
                    //解析指定元素
                    $.parser.parse($("#custSerForm #receiver"));
                }
                //收件电话
                if(res.data.receiverTel){

                    $("#custSerForm #receiverTel").textbox("setValue", res.data.receiverTel);
                    $("#custSerForm #receiverTel").textbox('readonly',true);

                    //设置验证属性
                    $("#custSerForm #receiverTel").textbox({validType:""});
                    //解析指定元素
                    $.parser.parse($("#custSerForm #receiverTel"));
                }else{
                    $("#custSerForm #receiverTel").textbox('readonly',false);
                    //设置验证属性
                    $("#custSerForm #receiverTel").textbox({validType:"phoneAndTelNum"});
                    //解析指定元素
                    $.parser.parse($("#custSerForm #receiverTel"));
                }

                //初始化收件地址省、市、区、乡镇 2018-07-02
                var receiveParams={editable:false,
                    provinceValue:res.data.recProvinceCode,
                    cityValue:res.data.recCityCode,
                    regionValue:res.data.recCountyCode
                };
                newpcrtAreaCascade("receiveProvince","receiveCity","receiveArea","receiveTown",receiveParams);
                if(res.data.recProvinceCode){
                    $("#receiveProvince").combobox('readonly',true);
                }else{
                    $("#receiveProvince").combobox('readonly',false);
                }
                if(res.data.recProvinceCode && res.data.recCityCode){
                    $("#receiveCity").combobox('readonly',true);
                }else{
                    $("#receiveCity").combobox('readonly',false);
                }
                if(res.data.recProvinceCode && res.data.recCityCode && res.data.recCountyCode){
                    $("#receiveArea").combobox('readonly',true);
                }else{
                    $("#receiveArea").combobox('readonly',false);
                }
                if(res.data.receiverAddress){
                    $("#custSerForm #receiveAddress").textbox("setValue", res.data.receiverAddress);
                    $("#custSerForm #receiveAddress").textbox('readonly',true);
                }else{
                    $("#custSerForm #receiveAddress").textbox('readonly',false);
                }

            }else{
                //zhaocan 2018-07-17
                window.parent.showTips("运单信息不存在");
                reducewaybillInfo();
            }
        }
    },"POST");
}
/**
 * 2018-07-17 清空运单信息。
 * 2018-07-17 运单信息恢复可编辑。
 * */
function  reducewaybillInfo(){
    //清空右侧运单信息
    $('#waybillNumId').text("");
    $('#sendAccSiteId').text("");
    $('#billType').text("");
    $("#carriageId").text("") ;
    $('#realWeightId').text("");
    $('#bulkWeightId').text("");
    $('#goodsPaymentId').text("");
    $('#signTimeId').text("");
    $('#recOrgCodeId').text("");
    $('#sendDateId').text("");
    $('#qtyId').text("");
    $('#operateEmpNameId').text("");
    $('#signManId').text("");
    $('#sendOrgName').text("");

    //清空左侧运单信息
    $("#custSerForm #expressInterior").textbox('clear');
    $("#custSerForm #sender").textbox('clear');
    $("#custSerForm #senderTel").textbox('clear');
    $("#sendProvince").combobox('clear');
    $("#sendCity").combobox('clear');
    $("#sendArea").combobox('clear');
    $("#sendTown").combobox('clear');
    $("#custSerForm #sendAddress").textbox('clear');

    $("#custSerForm #receiver").textbox('clear');
    $("#custSerForm #receiverTel").textbox('clear');
    $("#receiveProvince").combobox('clear');
    $("#receiveCity").combobox('clear');
    $("#receiveArea").combobox('clear');
    $("#receiveTown").combobox('clear');
    $("#custSerForm #receiveAddress").textbox('clear');


    $("#custSerForm #expressInterior").textbox('readonly',false);
    $("#custSerForm #sender").textbox('readonly',false);
    $("#custSerForm #senderTel").textbox('readonly',false);
    //设置验证属性
    $("#custSerForm #senderTel").textbox({validType:"phoneAndTelNum"});
    //解析指定元素
    $.parser.parse($("#custSerForm #senderTel"));
    $("#sendProvince").combobox('readonly',false);
    $("#sendCity").combobox('readonly',false);
    $("#sendArea").combobox('readonly',false);
    $("#custSerForm #sendAddress").textbox('readonly',false);
    $("#custSerForm #receiver").textbox('readonly',false);
    $("#custSerForm #receiverTel").textbox('readonly',false);
    //设置验证属性
    $("#custSerForm #receiverTel").textbox({validType:"phoneAndTelNum"});
    //解析指定元素
    $.parser.parse($("#custSerForm #receiverTel"));
    $("#receiveProvince").combobox('readonly',false);
    $("#receiveCity").combobox('readonly',false);
    $("#receiveArea").combobox('readonly',false);
    $("#custSerForm #receiveAddress").textbox('readonly',false);
}

/***
 * 发放记录列表
 * **/
function initRecordsInformationDataGrid(waybillNum){
    var columns = [[
        {field:'startNo',title: '起始单号'},
        {field:'endNo',title: '终止单号'},
        {field:'inoutTypeName',title: '类型'},
        {field:'dispenseDate',title: '发放/转让时间',formatter:function(value,row,index){
            return  formatData(value)
        }},
        {field:'useOrgName',title: '使用网点'},
        {field:'dispenseOrgName',title: '发放/转出网点'}
    ]]
    var dataGridParams = {
        url:G_CTX_PATH+"/cs/HomeScreenPopup/findDispenseList.do",
        Method:'POST',
        queryParams:{billCode:waybillNum},
        singleSelect : 'true',
        fitColumns : 'true',
        rownumbers: 'false'
    }
    newloadGrid('recordsInformationDataGrid', columns, dataGridParams);
}

/**
 * 子单信息列表
 * @param value
 */
function initChildInformationDataGrid(waybillNum){
    var columns = [[
        {field:'childBillCode',title: '运单编号',
            formatter: function(value, row, index){
                return '<strong class="colorjinji" onmouseover="showChildLogistics(' + value + ',this)" onmouseout="hideChildLogistics(\' + value + \',this)">'+value+'</strong>';
            }
        }
    ]]
    var dataGridParams = {
        url:G_CTX_PATH+"/cs/CsCommon/findChildWaybllInfo.do",
        Method:'POST',
        queryParams:{billCode:waybillNum},
        singleSelect : 'true',
        fitColumns : 'true',
        rownumbers: 'false'

    }
    newloadGrid('childInformationDataGrid', columns, dataGridParams);

}
/**
 * 展示子运单物流轨迹
 * */
function showChildLogistics(waybillNum,e){
    // initChildLogisticsInformationDataGrid(waybillNum);
    // var showbox = $("#childLogistics");
    // showbox.show();
    // $("#childLogisticsDataGrid").datagrid("resize");
    // showbox.removeClass('hidebox').addClass('showbox');
    // var topval =$(e).position().top;
    // showbox.css({'top':topval+100});
    // clearTimeout(0);
}
/**
 * 隐藏子运单物流轨迹
 * */
function hideChildLogistics(waybillNum,e){
    var showbox = $("#childLogistics");
    showbox.removeClass('showbox').addClass('hidebox');
    showbox.css({'top':'-1500%'});
}
/**
 * 子单物流轨迹列表
 * @param value
 */
function initChildLogisticsInformationDataGrid(waybillNum){
    var columns = [[
        {field:'createDate',title: '日期'},
        {field:'createTime',title: '时间'},
        {field:'trackMessage',title: '跟踪记录'}
    ]]
    var dataGridParams = {
        url:G_CTX_PATH+"/cs/HomeScreenPopup/findTraceInfo.do",
        Method:'POST',
        queryParams:{billCode:waybillNum},
        singleSelect : 'true',
        fitColumns : 'false',
        rownumbers: 'false',
        nowrap: 'false'
    }
    icsloadGrid('childLogisticsDataGrid', columns, dataGridParams);
}

/**
 * 提交
 * */
function  submitInfo(){
    //提交工单信息
    submitCsWoCustSer();
}

/***
 * 客户信息保存方法
 * **/
function saveCoustomerInformation() {
    var saveResult =false;
    //var id= $("#customerInformationForm #id").val();
    var url =G_CTX_PATH + "/cs/CsCustomerInfomation/saveByPhone.do";
    /* if(id){
     //更新客户信息
     url = G_CTX_PATH + "/cs/CsCustomerInfomation/customerInformationuUpd.do";
     }else{
     //新增客户信息
     url = G_CTX_PATH + "/cs/CsCustomerInfomation/csCustomerInformationAdd.do";
     }*/
    var data = serializeFormObj("customerInformationForm");
    data.phone =$("#custSerForm #customerTel").textbox('getValue');
    //客户省、市、区县、乡镇名称
    data.provinceName =$("#customerInformationForm #province").combobox('getText');
    data.cityName =$("#customerInformationForm #city").combobox('getText');
    data.countyName =$("#customerInformationForm #county").combobox('getText');
    data.townName =$("#customerInformationForm #town").combobox('getText');
    data.customerIdentity =$("#custSerForm #customerIdentity").combobox('getValue');
    /* uceAjax(url,data,function(res){
     //设置客户信息id
     $("#customerInformationForm #id").val(res.id);
     });*/
    $.ajax({
        type: "POST",
        url: url,
        data: data,
        async: false,
        success : function(res){
            //设置客户信息id
            $("#customerInformationForm #id").val(res.id);
            saveResult =true;
        }
    });
    return saveResult;
}

/**
 * 工单信息提交方法
 * */
/***
 *新建工单校验后保存方法
 * **/
function submitCsWoCustSer() {
    $('#submitButton').linkbutton('disable');//禁用提交按钮
    var customerInformationValidate = $("#customerInformationForm").form('validate');
    if(customerInformationValidate) {
        //校验运单号是否一致
        var customerTelSearch = $("#custSerForm #customerTelSearch").val();
        var customerTel = $("#custSerForm #customerTel").val();
        if (customerTelSearch != customerTel) {
            /*window.parent.rlliu*/showInfoMsg("请重新查询客户信息");
            $('#submitButton').linkbutton('enable');//启用提交按钮
            return;
        }
    }else{
        $('#submitButton').linkbutton('enable');//启用提交按钮
        return;
    }
    //工单数据校验
    var custSerFormValidate = $("#custSerForm").form('validate');
    if(custSerFormValidate){
        var waybillCode=$("#waybillNum").val();
        if(!waybillCode){//无运单号时校验是否需要输入运单
            if(checkRequireWayBillNum()){
                /*window.parent.rlliu*/showInfoMsg("请输入运单号");
                $('#submitButton').linkbutton('enable');//启用提交按钮
                return;
            }
        }else{
            //校验运单号是否一致
            var waybillNumSearch =$("#custSerForm #waybillNumSearch").val();
            if (waybillNumSearch !=waybillCode) {
                /*window.parent.rlliu*/showInfoMsg("请重新查询运单信息");
                $('#submitButton').linkbutton('enable');//启用提交按钮
                return;
            }
            //有运单时校运单的准确性，并判断工单是否为同类创建,是否允许创建
            //工单创建规则校验，呼叫中心工单：同一个来电号码，同一个运单，同一个类型，不可创建同类工单
            var sameCsWoCustSer =checkSameCsWoCustSer();
            if(sameCsWoCustSer){
                /*window.parent.rlliu*/showInfoMsg("同一个来电号码，同一个运单，同一个类型，不可创建同类工单");
                $('#submitButton').linkbutton('enable');//启用提交按钮
                return;
            }
            //验证是否允许创建
            var canCreate =checkCanCreate();
            if(canCreate==1){
                /*window.parent.rlliu*/showInfoMsg("只有做签收扫描之后才能创建");
                $('#submitButton').linkbutton('enable');//启用提交按钮
                return;
            }else if(canCreate==2){
                /*window.parent.rlliu*/showInfoMsg("只有签收扫描或派件之后才能创建");
                $('#submitButton').linkbutton('enable');//启用提交按钮
                return;
            }
        }
        //手动选择
        validateSel();
    }else{
        $('#submitButton').linkbutton('enable');//启用提交按钮
    }
}
/**
 *手动选择弹窗
 * **/
var selData;
function validateSel(){
    //构造工单数据
    var data =constructData();
    var dealOrgData =getFirstNodeDealOrg();
    if(dealOrgData && dealOrgData.woLabel){
        var woLabel=dealOrgData.woLabel
        data.woLabel=woLabel;
        if(woLabel=="1"){
            sumitCsWoCustSer(data);
        }else{
            if(dealOrgData.dealOrgRule){
                var selType =dealOrgData.dealOrgRule;
                data.dealOrgRule=selType;
                data.specialDeal="0";
                //openDialog("dlgSelOrg", '手动选择责任方网点/中心');
                var title ="";
                if(selType=="11"){
                    title="手动选择责任方网点"
                }else if(selType=="12"){
                    title="手动选择责任方中心"
                }else if(selType=="3"){
                    title="手动选择责任方"
                }else{
                    if(dealOrgData.dealOrgCode){
                        data.selDutyOrg=dealOrgData.dealOrgCode;
                        data.selDutyOrgType =dealOrgData.dealOrgType;
                        data.selDutyOrgName =dealOrgData.dealOrgName;
                        data.defaultFirstDutyOrgName = dealOrgData.dealDutyOrgName;
                        data.defaultFirstDutyOrgCode = dealOrgData.dealDutyOrgCode;
                        sumitCsWoCustSer(data);
                        return;
                    }else{
                        data.specialDeal="1";
                        title="请选择";
                        if(selType=="0"){
                            title=title+"寄件网点"
                        }else if(selType=="1"){
                            title=title+"派件网点"
                        }else if(selType=="2"){
                            title=title+"派件网点所属中心"
                        }else if(selType=="5"){
                            title=title+"运单发放网点"
                        }else if(selType=="6"){
                            title=title+"最后扫描节点"
                        }else if(selType=="7"){
                            title=title+"寄件网点所属中心"
                        }else if(selType=="10"){
                            title=title+"签收网点"
                        }else if(selType=="13"){
                            title=title+"签收网点中心或派件网点中心"
                        }
                    }
                }
                selData =data;
            }else{
                /*window.parent.rlliu*/showInfoMsg("工单流转配置规则信息不完善");
                $('#submitButton').linkbutton('enable');//启用提交按钮
                return;
            }
            //初始化责任方处理网点
            initSelDutyOrg(selType,title);
            createDialog("dlgSelOrg", title);
        }
    }else{
        /*window.parent.rlliu*/showInfoMsg("工单流转配置规则信息不完善");
        $('#submitButton').linkbutton('enable');//启用提交按钮
        return;
    }

}

/***
 *责任方网点弹窗选择确认
 * author:chutianhua
 * date:2018/6/26
 * **/
function sure(){
    var selDutyOrg =$("#selDutyOrg").combobox('getValue');
    var selDutyOrgCode =$("#dlgSelOrg #selDutyOrgCode").val();
    if(selDutyOrg!="" && selDutyOrg ==selDutyOrgCode){
        //关闭弹窗
        closeDialog('dlgSelOrg');
        var data =selData;
        data.selDutyOrg=selDutyOrg;
        data.selDutyOrgType =$("#dlgSelOrg #selDutyOrgType").val();
        data.selDutyOrgName =$("#dlgSelOrg #selDutyOrgName").val();
        //提交工单
        sumitCsWoCustSer(data);
    }else{
        /*window.parent.rlliu*/showInfoMsg("请选择责任方");
        return;
    }
}

/**
 * 验证是否允许创建工单
 * 由工单子类型和运单决定
 * 0允许 1：无签收扫描不允许（虚假签收） 2：无签收扫描/无派件不允许（不送货上门）*/
function checkCanCreate(){
    var canCreate =0;
    var url = G_CTX_PATH + "/cs/CsWoCustSer/checkCanCreate.do";
    var checkData ={
        orderChilType:$("#custSerForm  #orderChilType").combobox("getValue"),
        wayBillNum: $("#waybillNum").val(),
        source:$("#custSerForm #source").val()
    }
    $.ajax({
        type: "GET",
        url: url,
        data: checkData,
        async: false,
        success : function(result){
            if(result.data!=0){
                canCreate=result.data;
            }
        }
    });
    return canCreate;
}

/***
 * 提交前校验运单号是否必填
 * **/
function checkRequireWayBillNum(){
    var billRequire =false;
    var url = G_CTX_PATH + "/cs/CsWoCustSer/checkRequireWayBillNum.do";
    var checkData ={
        orderType:$("#custSerForm #orderType").combobox("getValue"),
        orderChilType:$("#custSerForm #orderChilType").combobox("getValue"),
        source:$("#custSerForm #source").val()
    }
    $.ajax({
        type: "GET",
        url: url,
        data: checkData,
        async: false,
        success : function(result){
            if(result.data==1){
                billRequire=true;
            }
        }
    });
    return billRequire;

}

/**
 * 处理规则
 * */
function getFirstNodeDealOrg(){
    var dealOrgData ={};
    var url = G_CTX_PATH + "/cs/CsWoCustSer/getFirstNodeDealOrg.do";
    var checkData ={
        orderChilType:$("#custSerForm  #orderChilType").combobox("getValue"),
        wayBillNum: $("#waybillNum").val(),
        source:$("#custSerForm #source").val(),
    }
    $.ajax({
        type: "GET",
        url: url,
        data: checkData,
        async: false,
        success : function(result){
            if(result.data){
                dealOrgData=result.data;
            }
        }
    });
    return dealOrgData;
}

/**
 * 工单创建规则校验，
 * 呼叫中心工单：同一个来电号码，同一个运单，同一个类型，不可创建同类工单
 * 校验未关闭的工单 2018-07-16
 * */
function checkSameCsWoCustSer(){
    var same =false;
    var url = G_CTX_PATH + "/cs/CsWoCustSer/checkSameCsWoCustSer.do";
    var checkData ={
        orderType:$("#custSerForm  #orderType").combobox("getValue"),
        orderChilType:$("#custSerForm  #orderChilType").combobox("getValue"),
        waybillNum: $("#waybillNum").val(),
        customerTel:$("#custSerForm #customerTel").val(),
        source:$("#custSerForm #source").val(),
        statusMul:"-1,0,1,2,3,4"
    }
    $.ajax({
        type: "GET",
        url: url,
        data: checkData,
        async: false,
        success : function(result){
            if(result.data==1){
                same=true;
            }
        }
    });
    return same;
}
/**
 *创建弹窗 $('#submitButton').linkbutton('enable');//启用提交按钮
 * **/
function  createDialog(id, title){
    //var h = parent.$("#mainTab")[0].offsetHeight;
    var h = 700;
    try {
        h = parent.$("#mainTab")[0].offsetHeight;
    } catch(err) {

    }
    $('#'+id).dialog({
        title: title,
        align : 'center',
        // 弹框top=滚动条到页面顶部的距离+（页面显示的高度-弹框的高度）/2
        top:$(document).scrollTop()+(h-300)*0.5,
        cache: false,
        modal: true,
        onClose:function(){
            $('#submitButton').linkbutton('enable');
        }
    });
    $('#'+id).dialog('open');
}

/*
 * *初始化责任方
 * */
/*function initSelDutyOrg(selType,title){
 $("#selDutyOrg").combotree({
 url:G_CTX_PATH + '/cs/omg/org/findAsyOrgTree.do',
 prompt:title,
 onBeforeLoad:function(node,param){
 param.orgFlag='CMS';
 if(node){
 param.orgCode=node.id;
 if(node.orgType == 10){//如果当前节点是总部，下一级节点查财务中心
 param.orgType = 20;
 }else{//否则查网点
 param.orgType = 30;
 }
 }else{
 param.orgCode=null;
 param.orgType=null;
 }
 },
 onSelect:function(node){
 if(selType=="3"){
 //手动选择网点/中心
 if(node.orgType != 30 && node.orgType!=20){
 showInfoMsg("请选择网点或财务中心");
 $("#selDutyOrg").combotree('setValue', '');
 $('#selDutyOrgType').val("");
 return false;
 }
 }else if(selType=="11"){
 if(node.orgType != 30 ){
 //手动选择网点
 showInfoMsg("请选择网点");
 $("#selDutyOrg").combotree('setValue', '');
 $('#selDutyOrgType').val("");
 return false;
 }
 }else if(selType=="12"){
 if(node.orgType != 20 ){
 //手动选择中心
 showInfoMsg("请选择财务中心");
 $("#selDutyOrg").combotree('setValue', '');
 $('#selDutyOrgType').val("");
 return false;
 }
 }else if(selType=="14"){
 //网服特配，不能选总部
 if(node.orgType == 10 ){
 showInfoMsg("不能选择总部");
 $("#selDutyOrg").combotree('setValue', '');
 $('#selDutyOrgType').val("");
 return false;
 }
 }
 $('#selDutyOrgType').val(node.orgType);
 }
 })
 }*/
//初始化责任方网点2018-07-18
function initSelDutyOrg(selType,title) {
    var par = {};
    if (selType == 11||selType == 10||selType == 5) {
        par["orgTypeStr"] = "30,40";
        par["defaultOrgType"] = "30";
    } else if (selType == 12 ||selType == 2||selType == 7||selType == 13) {
        par["orgTypeStr"] = "20";
        par["defaultOrgType"] = "20";
    } else if (selType == 14||selType == 6||selType == 3) {
        //网服特配
        par["orgTypeStr"] = "20,21,30,40";
        par["defaultOrgType"] = "20";
    }else if(selType == 0||selType == 1){
        par["orgTypeStr"] = "30,40";
        par["defaultOrgType"] = "30";
    }
    initDepartComboDB("selDutyOrg",par,title);
    $("#selDutyOrg").combobox({
        onSelect:function(node){
            $("#dlgSelOrg #selDutyOrgType").val(node.orgType);
            $("#dlgSelOrg #selDutyOrgName").val(node.orgFullName);
            $("#dlgSelOrg #selDutyOrgCode").val(node.baseOrgCode);
        }
    });
}
/***
 * 工单提交
 * **/
function sumitCsWoCustSer(data){
    var url =G_CTX_PATH+"/cs/CsWoCustSer/submit.do";
    //保存客户信息
    ajaxLoading('操作中,请稍后....');
    var saveResult =saveCoustomerInformation();
    if(!saveResult){
        ajaxLoadEnd();
        /*window.parent.rlliu*/showInfoMsg("保存客户信息失败");
        $('#submitButton').linkbutton('enable');
        return;
    }
    uceAjax(url,data,function (result) {
        ajaxLoadEnd();
        if(result.success){
            $("#custSerForm [name ='id']").val(result.data.id);
            //showInfoTip("操作成功");
            if(result.data.mqResult) {
                //showInfoTip("提交成功！");
                /*window.parent.rlliu.showIcsTips*/showTips("提交成功", "success");
                setTimeout(function(){closeCurrentTab()},1000);
                ///*window.parent.window.vm.rlliu*/closeCurrentTab();
            }else{
                /*window.parent.rlliu.showIcsTips*/showTips("MQ消息发送失败，请联系运维人员","error");
                $('#submitButton').linkbutton('enable');
            }
        }else{
            $('#submitButton').linkbutton('enable');
        }
    },"POST");
}

/**
 * 构造工单数据
 * */
function constructData(){
    var data =serializeFormObj("custSerForm");
    //工单类型名称
    data.orderTypeName =$("#custSerForm #orderType").combobox('getText');
    //工单子类型名称
    data.orderChilTypeName =$("#custSerForm #orderChilType").combobox('getText');
    //发件人省、市、区县、乡镇名称
    data.sendProvinceName =$("#custSerForm #sendProvince").combobox('getText');
    data.sendCityName =$("#custSerForm #sendCity").combobox('getText');
    data.sendAreaName =$("#custSerForm #sendArea").combobox('getText');
    data.sendTownName =$("#custSerForm #sendTown").combobox('getText');
    //收件人省、市、区县、乡镇名称
    data.receiveProvinceName =$("#custSerForm #receiveProvince").combobox('getText');
    data.receiveCityName =$("#custSerForm #receiveCity").combobox('getText');
    data.receiveAreaName =$("#custSerForm #receiveArea").combobox('getText');
    data.receiveTownName =$("#custSerForm #receiveTown").combobox('getText');
    //客户相关信息
    data.customerCode =$("#customerInformationForm #custCode").textbox('getValue');
    data.customerType =$("#customerInformationForm #custType").combobox('getValue');
    data.customerGrade =$("#customerInformationForm #custGrade").combobox('getValue');
    return data;
}
/**
 * 时间戳格式化
 * @param timestamp
 * @returns {*}
 */
function timestampToTime(timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000

    var y = date.getFullYear() + '-';
    var mm = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    var d = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return y+mm+d+h+m+s;
}

function openSendMessageDialog(){
    icsOpenDialog('sendMessageDialog','发送短信',300);
    $('#sendPhone').textbox('setValue',$('#customerTel').val());
    $('#sendContent').textbox('setValue','');
}

function openCustJoin(){
    window.open("http://www.uce.cn/affInfo/affInfoApply.html");
}

/**
 * 来电弹屏发送短信功能
 * chenqinglong
 * 20180725
 */
function sendPhoneMessage(){
    var formSendMessageValidate = $("#formSendMessage").form('validate');
    if(!formSendMessageValidate){
        return;
    }
    // $('#sendPhoneMessageButton').linkbutton('disable');
    uceAjax(G_CTX_PATH+"/cc/SmsMessage/sendPhoneMessage.do",serializeFormObj("formSendMessage"),function (result) {
        if(result.success){
            /*window.parent.rlliu.showIcsTips*/showTips("发送成功","success");
            closeDialog('sendMessageDialog');
        }
    },"POST");
}

// 2018-07-27 加此参数防止方法非必要执行
var checkOrder =false;
/**
 * 2018-07-27
 * 工单子类型为下单寄件的控制
 * */
function orderChildTypeSelect(orderChildTypeOpotion){
    var placeOrder =$("#custSerForm [name ='placeOrder']").val();
    if(orderChildTypeOpotion.idStr==placeOrder){
        selectPalceOrder();
    }else{
        unselectPlaceOrder();
    }
}
/**
 * 2018-07-27
 * 选择工单子类型下单寄件：
 * 必填和校验规则规则
 * */
function selectPalceOrder(){
    if(!checkOrder){
        $("#custSerForm #senderTitle").html('发件人<span style="color: red;">*</span>：');
        $("#custSerForm #senderTelTitle").html('发件号码<span style="color: red;">*</span>：');
        $("#custSerForm #receiverTitle").html('收件人<span style="color: red;">*</span>：');
        $("#custSerForm #receiverTelTitle").html('收件号码<span style="color: red;">*</span>：');
        $("#custSerForm #sendAddressTitle").html('发件地址<span style="color: red;">*</span>：');
        $("#custSerForm #receviceAddressTitle").html('收件地址<span style="color: red;">*</span>：');

        $("#custSerForm #sender").textbox({required:true});
        $("#custSerForm #senderTel").textbox({required:true});
        $("#custSerForm #receiver").textbox({required:true});
        $("#custSerForm #receiverTel").textbox({required:true});
        $("#custSerForm #sendProvince").combobox({required:true});
        $("#custSerForm #sendCity").combobox({required:true});
        $("#custSerForm #sendAddress").textbox({required:true});
        $("#custSerForm #receiveProvince").combobox({required:true});
        $("#custSerForm #receiveCity").combobox({required:true});
        $("#custSerForm #receiveAddress").textbox({required:true});
        var now_waybillNum = $("#waybillNum").textbox('getValue');
        if(now_waybillNum){
            reducewaybillInfo()
        }
        $("#waybillNum").textbox('clear');
        $("#waybillNum").textbox('readonly',true);
    }
    checkOrder =true;
}
/**
 * 2018-07-27
 * 选择工单子类型下单寄件：
 * 去除必填和校验规则规则
 * */
function unselectPlaceOrder(){
    if(checkOrder){
        $("#custSerForm #senderTitle").html('发件人：');
        $("#custSerForm #senderTelTitle").html('发件号码：');
        $("#custSerForm #receiverTitle").html('收件人：');
        $("#custSerForm #receiverTelTitle").html('收件号码：');
        $("#custSerForm #sendAddressTitle").html('发件地址：');
        $("#custSerForm #receviceAddressTitle").html('收件地址：');
        $("#custSerForm #sender").textbox({required:false});
        $("#custSerForm #senderTel").textbox({required:false});
        $("#custSerForm #receiver").textbox({required:false});
        $("#custSerForm #receiverTel").textbox({required:false});
        $("#custSerForm #sendProvince").combobox({required:false});
        $("#custSerForm #sendCity").combobox({required:false});
        $("#custSerForm #sendAddress").textbox({required:false});
        $("#custSerForm #receiveProvince").combobox({required:false});
        $("#custSerForm #receiveCity").combobox({required:false});
        $("#custSerForm #receiveAddress").textbox({required:false});
        $("#waybillNum").textbox('readonly',false);
    }
    checkOrder =false;
}
/**
 * 2018-09-18
 * 初始化责任网点下拉框
 * */
// function initDutyWebsiteCombobx(){
//     var par = {};
//     par["orgTypeStr"] = "20,21,30,40";
//     par["defaultOrgType"] = "20";
//     initDepartComboDB("dutyWebsite",par);
//     $("#dutyWebsite").combobox({
//         onSelect:function(node){
//             $("#custSerForm #dutyDepartBaseName").val(node.orgFullName);
//             $("#custSerForm #dutyDepartBaseCode").val(node.baseOrgCode);
//         }
//     });
// }


function formatTip3(e){
   return null;

}


function newpcrtAreaCascade(provinceId, cityId, regionId,townId,params) {
    var url = G_CTX_PATH + "/ccos/area/getAreaCodeByCondition.do";
    if (!provinceId) {
        console.error("provinceId不能为空");
        return;
    }
    $("#" + provinceId).combobox({
        valueField: params && params.valueField ? params.valueField : 'code',
        textField: params && params.textField ? params.textField : 'name',
        url: params && params.url ? params.url : url,
        editable: params && params.editable == false ? false : true,
        onBeforeLoad: function (param) {
            param.levelType = 1;
        },
        onLoadSuccess:function (data) {
            if(params.provinceValue){
                $('#' + provinceId).combobox('setValue', params.provinceValue);
            }else{
                $("#" + cityId).combobox('clear');
                $("#" + regionId).combobox('clear');
                $("#" + townId).combobox('clear');
                $("#" + cityId).combobox('loadData', {});
                $("#" + regionId).combobox('loadData', {});
                $("#" + townId).combobox('loadData', {});
            }
        },
        onSelect: !cityId || cityId == null ? function () {
        } : function (record) {
            console.log(record);
            if (cityId && cityId != null) {
                $("#" + cityId).combobox('clear');
                $("#" + cityId).combobox('loadData', {});
            }
            if (regionId && regionId != null) {
                $("#" + regionId).combobox('clear');
                $("#" + regionId).combobox('loadData', {});
            }
            if (townId && townId != null) {
                $("#" + townId).combobox('clear');
                $("#" + townId).combobox('loadData', {});
            }
            //2018-07-27
            if(!(params.provinceValue && params.provinceValue==record.code)){
                params.cityValue="";
                params.regionValue="";
                params.townValue="";
            }
            $("#" + cityId).combobox({
                valueField: params && params.valueField ? params.valueField : 'code',
                textField: params && params.textField ? params.textField : 'name',
                url: params && params.url ? params.url : url,
                editable: params && params.editable == true ? true : false,
                onBeforeLoad: function (param) {
                    param.levelType = 2;
                    param.parentCode = record.code;
                },
                onLoadSuccess:function (data) {
                    if(params.cityValue){
                        $('#' + cityId).combobox('setValue', params.cityValue);
                    }else{
                        $("#" + regionId).combobox('clear');
                        $("#" + townId).combobox('clear');
                        $("#" + regionId).combobox('loadData', {});
                        $("#" + townId).combobox('loadData', {});
                    }
                },
                onSelect: !regionId || regionId == null ? function () {
                } : function (record) {
                    if (regionId && regionId != null) {
                        $("#" + regionId).combobox('clear');
                        $("#" + regionId).combobox('loadData', {});
                    }
                    if (townId && townId != null) {
                        $("#" + townId).combobox('clear');
                        $("#" + townId).combobox('loadData', {});
                    }
                    //2018-07-27
                    if(!(params.cityValue && params.cityValue==record.code)){
                        params.regionValue="";
                        params.townValue="";
                    }
                    $("#" + regionId).combobox({
                        valueField: params && params.valueField ? params.valueField : 'code',
                        textField: params && params.textField ? params.textField : 'name',
                        url: params && params.url ? params.url : url,
                        editable: params && params.editable == true ? true : false,
                        onBeforeLoad: function (param) {
                            param.levelType = 3;
                            param.parentCode = record.code;
                        },
                        onLoadSuccess:function (data) {
                            if(params.regionValue){
                                $('#' + regionId).combobox('setValue', params.regionValue);
                            }else{
                                $("#" + townId).combobox('clear');
                                $("#" + townId).combobox('loadData', {});
                            }
                        },
                        onSelect: !townId || townId == null ? function () {
                        } : function (record) {
                            if (townId && townId != null) {
                                $("#" + townId).combobox('clear');
                                $("#" + townId).combobox('loadData', {});
                            }
                            //2018-07-27
                            if(!(params.regionValue && params.regionValue==record.code)){
                                params.townValue="";
                            }
                            $("#" + townId).combobox({
                                valueField: params && params.valueField ? params.valueField : 'code',
                                textField: params && params.textField ? params.textField : 'name',
                                url: params && params.url ? params.url : url,
                                editable: params && params.editable == true ? true : false,
                                onBeforeLoad: function (param) {
                                    param.levelType = 4;
                                    param.parentCode = record.code;
                                },
                                onLoadSuccess:function (data) {
                                    if(params.townValue){
                                        $('#' + townId).combobox('setValue', params.townValue);
                                    }
                                }
                            });
                        }

                    })
                }
            })
        }

    })
}